Introduction

This is a notebook created to document a generic Trade Engine for backtesting and paper trading. It includes a review of the architecture, the type of backtests supported, and a library of documented examples to demonstrate the functionality.

Setup

Python Libraries

In [1]:
%load_ext pyinstrument

import os
print( os.environ['PYTHONPATH'] )
%reload_ext autoreload
%autoreload 2


# Python ≥3.6 is required
import sys
assert sys.version_info >= (3, 6)

# Common imports
import numpy as np
import os
import pandas as pd
import yfinance as yf
import feather
import tables
import ta
from datetime import datetime

# Ignore useless warnings (see SciPy issue #5998)
import warnings
warnings.filterwarnings(action="ignore", message="^internal gelsd")
warnings.filterwarnings("ignore", category=RuntimeWarning) 

import sqlalchemy
print(sqlalchemy.__version__)
from sqlalchemy.orm import with_polymorphic

# ignore lazy loading warnings
from sqlalchemy import exc as sa_exc
with warnings.catch_warnings():
   warnings.simplefilter("ignore", category = sa_exc.SAWarning)

from trade_engine.persist.DBLayer                             import DBLayer
from trade_engine.persist.DBSchema                            import DBSchema
/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/src:/Users/gustavozambrana/Google Drive/Python:/Users/gustavozambrana/Google Drive/Python/Projects/Market_Data/src
1.4.0b3

Logging

In [2]:
import logging
from logging.config import fileConfig
fileConfig('/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/log/logging.ini')

#logger = logging.getLogger('dev')
import logging
logging.basicConfig(level=logging.WARN)
logging.getLogger().setLevel(logging.WARN)

Database

In [5]:
myDBLayer = DBLayer()

# ***
# *** Connect String for SQL Lite db in memory
# ***
# sqliteConnString = 'sqlite:///:memory:' 
# myDBLayer.connect( connString = sqliteConnString )

# ***
# *** Connect String for SQL Lite db file
# ***

# dbTradeEngTestPath = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/db/dbTradeEngTest.db'
# ConnString = 'sqlite:///' + dbTradeEngTestPath

# ***
# *** Postgres DB
# ***

ConnString = 'postgresql+pg8000://postgres:postgres@localhost:7777/trade_engine_dev_db'

# *** Connect to DB, Create DB Schema if not already created, and acquired a DB session

myDBLayer.connect( connString = ConnString )
DBSchema.createDBSchema()  
session = DBLayer.getSession()

Optional Drop Table(s)

In [4]:
DBSchema.dropAll()

Trade Engine Overview

Architecture

  • The main features of the trade engine are:

    • Performs a backtest for a single trade strategy or a portfolio of trade strategies

    • Support different kinds of backtests and optimizations of hyper-parameters per trade strategy

    • Analyzed out-of-sample performance for trade strategies and/or portfolio

      • Support Technical Analysis Models, as well as AI Based Models to model all trade actions in a trade, that is:

        • Enter, Exit, Position Sizing, Stop-Loss, Trail-Stop-Loss, etc.

        • Technical Analysis Models are models that:

          • Do not need to be fitted prior to a backtest, such as: SMA, RSI, Bollinger Bands, MACD, etc.
        • AI Based Models are any models that:

          • Required to be fitted with a training and validation date ranges that do not overlapped the backtest period, such as Machine Learning, Deep Learning, and Reinforcement Learning Models.
    • Support ensemble models for any trade action in a Trade Strategy, i.e.:

      • N number of models for entering a trade
      • M number of models to exit a trade
      • K number of models to decide on stop-loss %
    • Support mixing Technical Analysis and AI Based Models in ensembles of any trade action

    • Support persisting all information to execute a backtest in a Relational Database, as well as the results

    • Setup the architecture to enable distributed cloud execution of backtests

  • The following are the logical components to define a backtest:

    • A **Trade Strategy** is defined via a Trade Asset Register Item, which is an object that contains all components necessary to execute in a backtest

    • A **Trade Asset Register Item** has several components:
      • Trade Strategy Model
        • Manages the actions to perform in a trade strategy (Enter, Exit, Position Size, Stop-Lost, etc.)
        • Has a reference to a Market Data Manager Object to get the required data
      • Trade Asset Investment Manager
        • Manages the funds allocated to the trade strategy
      • Broker
        • Open, closes, and updates trades (Simulated or Paper-Trading)

    • A **Trade Strategy Model** has different models controlling the different actions in a trade
      • A list of Enter Action models, and corresponding policy rules for the ensemble (required)
      • A list of Exit Action models, and corresponding policy rules for the ensemble (optional)
      • List of models for all other actions and their ensemble policies (optional)

    • A **Portfolio Register Item** defines a portfolio
      • It is an object that contains a list of Trade Asset Register Items and a Portfolio Investment Manager
      • The Portfolio Investment Manager, manages the funds for the entire portfolio, and re-balances the funds for the portfolio, if configured to do so, periodically.

  • Building and Executing any type of backtest consist of the following steps:

    1. Define a Market Data Object that has all the securities price data
    2. Define a Broker Object to execute trades (Simulation, Paper Trading )
    • Define the models for the trade strategy
      • All models for all trade actions are defined via JSON configuration
      • The only requirement is one entry model, all others are optional
    • Create a Trade Strategy Register Item or Portfolio Register Item object
      • supported via a high level API
    • Execute Backtest
      • Select the desire backtest type for execution (see next section for supported types)
    • Analysis of the Results
      • Each backtest object provides methods to output metadata, performance metrics, trades detail data, trades summary data, etc. (see Data section for a definition of all data created, and explanation of each parameter output)
    • Generate Reports
      • Full teardown sheets are supported for each trade strategy or portfolio, as well as comparison against a benchmark (see Reports section under Examples)

Backtests

There are different types of backtest supported, the following is a list of the different backtests types and their objectives:

**1. Backtest**

  • Executes a Trade Register Item or Portfolio Register Item in a test period
  • If any of the Trade Register Items contains at least one trade-action rule that is modeled via an AI Model, the modeled Fit date ranges must be specified (Training and Validation )
  • A Backtest generates a large set of performance statistics to analyze the trade strategy, and a set of trade performance plots (supported via the package: https://github.com/ranaroussi/quantstats )

**2. WFA Backtest**

  • Re-fit all AI models that a given trade strategy or portfolio depends during a backtest
  • The re-fit periodicity and size are configurable parameters, for ex:
    • Re-fit all AI Models every 3 months during a backtest, as the backtest progresses, it uses the updated fitted models for the action rules.

**3. Sliding Window WFA Backtest**

  • Executes a set of WFA-Backtests by sliding or extending the Training, Validation and Test Periods through time, and by also varying (optionally) the re-fit frequency per backtest.
  • Purpose of these set of backtest is to analyze the out-of-sample performance for trade strategies and/or portfolios through different market regimes.

**4. Grid-Search Backtest**

  • Run a set of backtests by varying a list of hyper-parameters for each Trade-Strategy or set of Trade Strategies.
  • Similar in spirit to https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html
  • The Grid-Search Backtest can be applied to a regular Backtest, a WFA-Backtest, or as an option in a Sliding-Window WFA Backtest; in the latter, the grid-search will be conducted prior to each sliding-window iteration.
  • The main purpose of this type of backtest, it is optimizing hyper parameters for one or more trade strategies in a backtest or per sliding-window shifting.

**5. Production-Sim Backtest**

  • The objective of this backtest is to allow the selection of a one or more trade strategies over time for trading. The trade strategies can vary over time, and have different hyper-parameters resulting from an optimization via the Grid-Search Backtest. Subsequently to selecting n number of Trade Strategies, evaluate them out-of-sample, and repeat this process many times through time using the Sliding Window WFA Backtest.
  • The main idea is that the trade strategies selected for trading can vary over time, as well as the hyper-parameters of the underlying models of the trade strategies, and the re-fit frequency. One must be careful to carry this process and selection process up to certain time, and only apply once out-of-sample, otherwise, one is adding bias to the selection process.

Graphical Representation

Data

For each trade strategy in a **Backtest or WFA-Backtest** metadata and performance metrics are generated.

Metadata

             Parameter                                               Description
         -----------------------         --------------------------------------------------------------------
     0   ta_reg_item_name                Trade Strategy Name
     1   ta_reg_item_id                  Database ID if persisted
     2   is_portfolio                    Indicates if entry correspond to Portfolio summary or T.S.
     3   trade_asset                     Trade Asset associated with Trade Strategy 
     4   model_type                      [ Static or Dynamic ], Static ties T.S. to one Trade Asset
     5   order_type                      Simulation for submitting a trade, valid options:
                                           [Market, Stop-Loss, Trail-Stop-Loss, Stop-Loss & Trail-Stop-Loss ]
     6   trade_on_etf                    If underlying trade corresponds to a leverage ETF for the Trade Asset
     7   enter_model_unique_name         Unique name for enter action model across all Trade Strategies in
                                         the portfolio. For example:
                                            [ ts_sma_1, ts_sma_2 ] correspond to two different SMA T.S.
                                            in the portfolio, configured with different parameters for
                                            modeling enter signals
     8   enter_ensemble_model            Yes = Ensemble Enter Model, No = Individual enter model    
     9   enter_num_models                Number of enter models in the trade strategy
     10  enter_model                     Enter action model, that is: SMA, MACD, LSTM, GRU, etc. or 
                                         composite if an ensemble enter trade strategy in place
     11  enter_model_type                Type of model, either TA (Technical Analysis signal based) or 
                                         AI (Artificial Intellgence based, either ML or DL)
     12  enter_models                    List of all enter models in the trade strategy, if non-ensemble,
                                         this list has only one item, matching the enter_model param
     13  exit_model_unique_name          Unique name for exit action model across all Trade Strategies in
                                         the portfolio.
     14  exit_ensemble_model             Yes = Ensemble Exit Model, No = Individual exit model 
     15  exit_num_models                 Number of exit models in the trade strategy
     16  exit_model                      Exit action model, that is: SMA, MACD, LSTM, GRU, etc. or 
                                         composite if an ensemble exit trade strategy in place
     17  exit_model_type                 Type of model, either TA (Technical Analysis signal based) or 
                                         AI (Artificial Intellgence based, either ML or DL)         
     18  exit_models                     List of all exit models in the trade strategy, if non-ensemble,
                                         this list has only one item, matching the exit_model param   
     19  stop_model_unique_name          Unique name for stop action model across all Trade Strategies in
                                         the portfolio. For example:
                                            [ ts_stop_1, ts_stop_2 ] correspond to two stop action models     
     20  stop_ensemble_model             Yes = Ensemble Stop Model, No = Individual stop model      
     21  stop_num_models                 Number of stop models in the trade strategy          
     22  stop_model                      Stop action model, that is: ATR, AI_ATR, etc. or 
                                         composite if an ensemble stop trade strategy in place             
     23  stop_model_type                 Type of model, either TA (Technical Analysis signal based) or 
                                         AI (Artificial Intellgence based, either ML or DL)          
     24  stop_models                     List of all stop models in the trade strategy, if non-ensemble,
                                         this list has only one item, matching the stop_model param           
     25  test_period_len_days            For Trade Strategies with at least one AI action model, the 
                                         duration of the testing period measured in days. 
                                         This corresponds to the backtest date range.
     26  tr_period_len_days              For Trade Strategies with at least one AI action model, the 
                                         duration of the training period measured in days.          
     27  val_period_len_days             For Trade Strategies with at least one AI action model, the 
                                         duration of the validation period measured in days.

Performance Metrics

    - Generated by Python QuantStats package ( https://github.com/ranaroussi/quantstats )
    - Refer to their documentation for description

     1  index                       
     2  Start Period                
     3  End Period                  
     4  Risk-Free Rate              
     5  Time in Market              
     6  Cumulative Return           
     7  CAGR%                       
     8  Sharpe                      
     9  Sortino                     
     10  Sortino/√2                  
     11  Max Drawdown                
     12  Longest DD Days             
     13  Volatility (ann.)           
     14  Calmar                      
     15  Skew                        
     16  Kurtosis                    
     17  Expected Daily %            
     18  Expected Monthly %          
     19  Expected Yearly %           
     20  Kelly Criterion             
     21  Risk of Ruin                
     22  Daily Value-at-Risk         
     23  Expected Shortfall (cVaR)   
     24  Gain/Pain Ratio             
     25  Gain/Pain (1M)              
     26  Payoff Ratio                
     27  Profit Factor               
     28  Common Sense Ratio          
     29  CPC Index                   
     30 Tail Ratio                  
     31  Outlier Win Ratio           
     32  Outlier Loss Ratio          
     33  MTD                         
     34  3M                          
     35  6M                          
     36  YTD                         
     37  1Y                          
     38  3Y (ann.)                   
     39  5Y (ann.)                   
     40  10Y (ann.)                  
     41  All-time (ann.)             
     42  Best Day                    
     43  Worst Day                   
     44  Best Month                  
     45  Worst Month                 
     46  Best Year                   
     47  Worst Year                  
     48  Avg. Drawdown               
     49  Avg. Drawdown Days          
     50  Recovery Factor             
     51  Ulcer Index                 
     52  Avg. Up Month               
     53  Avg. Down Month             
     54 Win Days %                  
     55  Win Month %                 
     56  Win Quarter %               
     57  Win Year %                  

Trade Transaction Detail Data

             Parameter                                               Description
         -----------------------            ----------------------------------------------------------------- 
 0   ta_reg_item_name                               
 1   ta_reg_item_id                                
 2   tr_num                                          
 3   tr_id                                          
 4   broker_id                                     
 5   trade_asset                                    
 6   trade_funds_start                             
 7   trade_funds_end                               
 8   trade_return_end                              
 9   trade_type                                     
 10  enter_trade_next_open_period                     
 11  trade_clerance_percent                       
 12  trade_on_etf                                     
 13  trade_completed                                 
 14  trade_status                                   
 15  trade_status_msg                              
 16  order_type                                     
 17  trade_entered_executed_price                  
 18  trade_exited_executed_price                  
 19  num_shares                                     
 20  trade_entered_date                     
 21  trade_close_date                       
 22  transaction_fee                                
 23  transaction_tax                                
 24  total_transaction_cost                         
 25  stop_loss_per                                 
 26  trail_stop_loss_per                           
 27  trade_high_price_at_exit                      
 28  trade_low_price_at_exit                       
 29  trade_high_price_prev_period                  
 30  trade_low_price_prev_period                   
 31  close_stock_price_for_trade_exit_date        
 32  high_stock_price_for_trade_exit_date          
 33  low_stock_price_for_trade_exit_date           
 34  open_stock_price_for_trade_exit_date         
 35  final_stop_loss_triggered_price               
 36  final_trail_stop_loss_triggered_price        
 37  trade_exit_cause                              

Examples

Summary

This section gives an overview of the current examples provided, and general instructions

  • The examples are categorized as follows:

    1. **Backtest**

    2. **WFA Backtest**

    3. **Sliding Window WFA Backtest**

    4. **Grid Backtest**

    5. **Production Sim Backtest**

    6. **Reports**

    7. **Other**

  • There is a common set of imports for all examples at the beginning that is required to be imported

  • The examples should be reviewed sequentially, as they get more complex and present more features as they progress. In addition, some examples refered to explanations and models from previous ones.

  • Every example has a detail description of the backtest at the start, the trade strategies in the backtest, the trade actions configured and their supporting models, their Training and Validation Periods (only required if at least one AI model is present in the backtest), Test Period, etc.

  • Saving and Re-Storing any objects to a database is optional, in some examples is presented, but it is the same procedure for all examples/objects. In all cases, saving an object, cascades and saves all children objects, and retreiving an object, retrieves all children objects (lazy loading). Refer to SQLAlchemy for additional details.

Examples:

  • **Backtest**

    1. Nasdaq ETF - Yahoo Finance Market Data - SMA Trade Strategy

    • **Type :** Trade Strategy
    • **Enter & Exit Models :** SMA
    • **Market Data Source:** Yahoo Finance
    • **Description:** One trade strategy: Nasdaq using Simple Moving Average(SMA) for entering/exiting a trade

    2. Cottons Futures - Quandal Market Data - SMA Trade Strategy

    • **Type :** Trade Strategy
    • **Enter & Exit Models :** SMA
    • **Market Data Source:** Quandal
    • **Description:** One trade strategy: Cotton's Futures using Simple Moving Average(SMA) for entering/exiting a trade

    3. Nasdaq ETF - Yahoo Finance Market Data - LSTM Trade Strategy

    • **Type :** Trade Strategy
    • **Enter & Exit Models :** LSTM
    • **Market Data Source:** Yahoo Finance
    • **Description:** One trade strategy: Nasdaq ETF using a LSTM-Model for entering/exiting a trade

    4. Portfolio A: Buy-and-Hold and SMA Trade Strategies for US Indixes

    • **Type :** Portfolio
    • **Enter & Exit Models :** SMA
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using SMA

    5. Portfolio B: Buy-and-Hold and AI LSTM based Strategies for US Indixes

    • **Type :** Portfolio
    • **Enter & Exit Models :** LSTM
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using LSTM AI Model

    6. Portfolio C: Buy-and-Hold and Multiple Configured SMA Trade Strategies for US Indixes

    • **Type :** Portfolio
    • **Enter & Exit Models :** Seven distinct SMA Models
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Twenty-One trade strategies: Nasdaq, S&P 500, and DOW Jones using different SMA Models
        1. Three ensemble trade strategies based on all SMA models, one per US Index

    7. Portfolio D: Buy-and-Hold and Multiple Configured LSTM Trade Strategies for US Indixes

    • **Type :** Portfolio
    • **Enter & Exit Models :** Seven distinct LSTM Models
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Twenty-One trade strategies: Nasdaq, S&P 500, and DOW Jones using different LSTM Models
        1. Three ensemble trade strategies based on all LSTM models, one per US Index

    8. Portfolio E: Buy-and-Hold and Eleven Distinct Technical Analysis Based Trade Strategies for US Indixes

    • **Type :** Portfolio
    • **Enter & Exit Models :** Elevent distinct Technical-Analysis (TA) Models
      • SMA, Bollinger Bands, MACD, RSI, Stochastic-RSI, ADX, KAMA, TSI, ForceIndex, MFI, SMA
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Thirty-Three trade strategies: Nasdaq, S&P 500, and DOW Jones for each TA Model
        1. Three ensemble trade strategies based on all TA models, one per US Index

    9. Portfolio F: Buy-and-Hold and Multiple Configured AI Modeled Trade Strategies for US Indixes

    • **Type :** Portfolio
    • **Enter & Exit Models :** Eight distinct AI based models
      • GRU, LSTM, Conv1d-GRU, Conv1d-LSTM, Wavenet, Wavenet-GRU, GRU, Wavenet-LSTM
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Twenty-Four trade strategies: Nasdaq, S&P 500, and DOW Jones for each AI trading model
        1. Three ensemble trade strategies based on all AI trading models, one per US Index

    10. Portfolio G: All Trade Strategies in Portfolio E and F

    • **Type :** Portfolio
    • **Enter & Exit Models :** Eight distinct AI based models and Eleven TA based models
      • GRU, LSTM, Conv1d-GRU, Conv1d-LSTM, Wavenet, Wavenet-GRU, GRU, Wavenet-LSTM
      • SMA, Bollinger Bands, MACD, RSI, Stochastic-RSI, ADX, KAMA, TSI, ForceIndex, MFI, SMA
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Fifty-Seven trade strategies: Nasdaq, S&P 500, and DOW Jones for each AI and TA trading model
        1. Three ensemble trade strategies based on all AI and TA trading models, one per US Index

    11. Portfolio H: Utilized Leveraged ETFs for Trading on The Model Trade-Asset

    • **Type :** Portfolio
      • This example shows the effect of creating a Trade Strategy with a given model for any trade asset, but actually, trading on an underlying leveraged ETF for that security
    • **Enter & Exit Models :** Same as Portfolio F
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. Five Trade Strategies are executed with ETF-on
        1. Five Trade Strategies are executed with ETF-off to show effect of ETF-on trading
        1. Three ensemble trade strategies based on all AI and TA trading models, one per US Index, for the ETF-on Trade Strategies
        1. Three ensemble trade strategies based on all AI and TA trading models, one per US Index, for the non-ETF Trade Strategies

    12. Portfolio I: Monthly Rebalance of Funds in a Portfolio

    • **Type :** Portfolio
    • **Enter & Exit Models :** Same strategies as defined and explained in Portfolio C
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Portfolio Investment Manager configured to balance funds monthly, using an equal weights policy

    13. Portfolio J: Trade Strategies with different Market Data Sources (Quandal, YahooFinance, User-Defined DataFrame)

    • **Type :** Portfolio
    • **Enter & Exit Models :**
      • Multiple SMA Models, and LSTM, GRU, MACD, and RSI Models defined to use with each trading asset
    • **Market Data Source:** Yahoo Finance, Quandal, User-Defined DataFrame
    • **Description:**
      • This example shows how to configured a portfolio with trade strategies that depend on different market data sources.
      • Each trade strategy is associated with one Market Data Source, which may or may not be shared with other trade strategies.
      • This example also shows how to use any market data with the engine, provided it is in a Pandas DataFrame (details discussed in the example, regarding the format of the data frame)

    14. Portfolio K: Buy-and-Hold and Multiple Configured SMA Trade Strategies for US Indixes, with Stop Models

    • **Type :** Portfolio
      • This example shows the effect of using a variety of stop models with SMA models to enter/exit in a trade strategy
    • **Enter & Exit Models :** Same as Portfolio C
    • **Stop Models :**
      • Eight different stop-models
        • Stop Loss order with specified stop-loss percent limit
        • Trail Stop Loss order with specified trail-stop-loss percent limit
        • Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
        • Five different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived stop-loss and trail-stop-loss percent limits using the Average True Range(ATR) algorithm
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. 219 Trade Strategies, this is the set of permutations of all enter/exit models, stop models, ensemble strategies, and securities in the portfolio
        1. The backtest is executed for 20 years, 2001-2020

    15. Portfolio L: Buy-and-Hold and Multiple Configured TA Trade Strategies for US Indixes, with Stop Models

    • **Type :** Portfolio
      • This example shows the effect of using a variety of stop models with a variety of Technical Analysis (TA) models to enter/exit in a trade strategy
    • **Enter & Exit Models :** Same as Portfolio E
    • **Stop Models :**
      • Eight different stop-models
        • Stop Loss order with specified stop-loss percent limit
        • Trail Stop Loss order with specified trail-stop-loss percent limit
        • Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
        • Three different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived stop-loss and trail-stop-loss percent limits using the Average True Range(ATR) algorithm
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. 219 Trade Strategies, this is the set of permutations of all enter/exit models, stop models, ensemble strategies, and securities in the portfolio
        1. The backtest is executed for 20 years, 2001-2020

    16. Portfolio M: Buy-and-Hold and Multiple Configured AI Trade Strategies for US Indixes, with Stop Models

    • **Type :** Portfolio
      • This example shows the effect of using a variety of stop models with AI models to enter/exit in a trade strategy
    • **Enter & Exit Models :** Same as Portfolio F
    • **Stop Models :**
      • Four different stop-models
        • Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
        • Three different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived stop-loss and trail-stop-loss percent limits using the Average True Range(ATR) algorithm
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. 138 Trade Strategies, this is the set of permutations of all enter/exit models, stop models, ensemble strategies, and securities in the portfolio
        1. The backtest is executed for 1 year, 2009

    17. Portfolio N: Buy-and-Hold and Multiple Configured AI Trade Strategies for US Indixes, with AI based Stop Models

    • **Type :** Portfolio
      • This example shows the effect of using a variety of stop models with AI models to enter/exit in a trade strategy
    • **Enter & Exit Models :** Same as Portfolio F
    • **Stop Models :**
      • Five different stop-models
        • Different Combine Stop-Loss & Trail-Stop-Loss models, configured with AI derived stop-loss and trail-stop-loss percent limits using LSTM, GRU, etc.
        • The AI time series models are utilized to forecast next day True Range for the stock, and use that information to derive the percent stop and trail-stop limits.
    • **Market Data Source:** Yahoo Finance
    • **Description:** Portfolio with the following trade strategies:
        1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold strategy
        1. 138 Trade Strategies, this is the set of permutations of all enter/exit models, stop models, ensemble strategies, and securities in the portfolio
        1. The backtest is executed for 1 year, 2009


  • **WFA Backtest**

    1. WFA-Backtest-1

    • **Type :** Portfolio
    • **Enter & Exit Models :** Same entry/exit models configured in Portfolio F
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Re-fit AI models every four-months during the backtest
      • Don't anchored the training-set

    2. WFA-Backtest-2

    • **Type :** Portfolio
    • **Enter & Exit Models :** Subset of the entry/exit models in Portfolio G
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Re-fit AI models every six months during the backtest
      • Anchored the training-set

    3. WFA-Backtest-3

    • **Type :** Portfolio
    • **Enter & Exit Models :** Same entry/exit models configured in Portfolio G
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Re-fit AI models every six months during the backtest
      • Training-set is not anchored


  • **Slide Window WFA Backtest**

    1. SW-WFA-Backtest 1

    • **Type :** Portfolio
    • **Enter & Exit Models :** Same entry/exit models configured in Portfolio F
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Backtest 1: Re-fit AI models every three months
      • Backtest 2: Re-fit AI models every six months
      • Fixed Training and Validation periods
      • Training-set is not anchored during a backtest
      • 30 Trade Strategies

    2. SW-WFA-Backtest 2

    • **Type :** Portfolio
    • **Enter & Exit Models :** Same entry/exit models configured in Portfolio F
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Re-fit AI models every three months within a backtest
      • Slide Datasets by one year increments for five consecutive years
      • Training-set is not anchored in outer slide window or during a backtest
      • 30 Trade Strategies

    3. SW-WFA-Backtest 3

    • **Type :** Portfolio
    • **Enter & Exit Models :** Same entry/exit models configured in Portfolio G
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Re-fit AI trading models every 3 months within a backtest and anchored within the backtest
      • Fit datasets are anchored and duration increased by one year increments for five consecutive years
        • Every sliding window iteration, the training set duration is increased by 9 months and the validation set by 3 months, the test set is just shifted by one year.
        • Training-set is anchored in outer slide window and also anchored in the re-fitting process during a backtest
        • Backtest period from 2003 to 2007, sliding window is one-year
      • 63 Trade Strategies

    4. SW-WFA-Backtest 4

    • **Type :** Portfolio
    • **Enter & Exit Models :** Portfolio has the same entry/exit models configured in Portfolio G and C
    • **Stop Models :**
      • Five different stop-models
        • One model with fix values for stop-loss and trail-stop loss
        • Four ATR models, each configured with different hyper parameters
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • The total number of permutations of all trade strategies for all securities, enter/exit
        models, stop models, and ensemble models is 633
      • Re-fit all AI trading models every 4 and 12 months within a backtest and not anchored within the backtest
      • Training-set is not anchored in outer slide window and also not anchored in the re-fitting process during a backtest
      • Sliding Window Backtest executed from 2001 to 2010, with one year increments for the sliding window.
        • Two backtests are executed per year, the first one refits the AI models in each Trade Strategy every 4 months, the second one only at the start of the backtest

    5. SW-WFA-Backtest 5

    • **Type :** Portfolio
    • **Enter & Exit Models :** Portfolio has the same entry/exit models configured in Portfolio C
    • **Stop Models :**
      • Eight different stop-models
        • Stop Loss order with specified stop-loss percent limit
        • Trail Stop Loss order with specified trail-stop-loss percent limit
        • Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
        • Five different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived stop-loss and trail-stop-loss percent limits using the Average True Range(ATR) algorithm
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • The total number of permutations of all trade strategies for all securities, enter/exit
        models, stop models, and ensemble models is 210
      • Sliding Window Backtest executed from 2001 to 2020, with one year increments for the sliding window.


  • **Grid Backtest**

    To be added



  • **Production Sim Backtest**

    To be added



  • **Reports**

    1. Create Full Tearsheet Reports

    • **Description:**
      • Create a full tearsheet report for a backtest
      • Create a tearsheet report that compares a backtest against a benchmark strategy

    2. Create HTML Tearsheet Reports

    • **Description:**
      • Similar to 1. but saved to an HTML file.


  • **Other**

    1. Trade Fee Policy

    • **Type :** Trade Strategy
    • **Models :** SMA
    • **Market Data Source:** Yahoo Finance
    • **Description:**
      • Demonstrate how to apply a flat broker fee per trade transaction or percent based fee per transaction amount


Backtest

In [6]:
# *** Imports required for running Trade Strategy examples

from trade_engine.model.TradeStrategyBaseModelPersist                import TradeStrategyBaseModelPersist
from trade_engine.model.TradeStrategyModelStatic                     import TradeStrategyModelStatic
from trade_engine.model.TradeStrategyMarketDataMng                   import TradeStrategyMarketDataMng
from trade_engine.model.MarketDataPeriod                             import MarketDataPeriod
from trade_engine.ts_actions.generate.TradeStrategyActionGenerator   import TradeStrategyActionGenerator
from trade_engine.ts_actions.generate.TradeAssetRegisterItemGenerator import TradeAssetRegisterItemGenerator
from trade_engine.ts_actions.generate.TradeStrategyConfigData        import TradeStrategyConfigData
from trade_engine.investment_manager.TradingAssetInvMngBase          import TradingAssetInvMngBase
from trade_engine.registry.TradingAssetExecutionType                 import TradingAssetExecutionType
from trade_engine.registry.TradingAssetRegisterItem                  import TradingAssetRegisterItem
from trade_engine.broker.SimBrokerTrading                            import SimBrokerTrading
from trade_engine.execution.BacktestExecution                        import BacktestExecution
from trade_engine.dataset_def.DatasetDef                             import DatasetDef, DatasetType
from trade_engine.dataset_def.FitDatasetsDef                         import FitDatasetsDef
from trade_engine.reports.BacktestReports                            import BacktestReports

# *** Additional Imports required for running Portfolio examples

from tradeg.market_data.MarketData                                   import MarketData
from trade_engine.model.TALibPipelineBuilder                         import TALibPipelineBuilder
from trade_engine.model.TradeStrategyModelPipelineDataMng            import TradeStrategyModelPipelineDataMng
from trade_engine.enter_ts.TradeEnterClassicStrategy                 import TradeEnterClassicStrategy
from trade_engine.exit_ts.TradeExitClassicStrategy                   import TradeExitClassicStrategy
from trade_engine.model.classic.CacheTradingModel                    import CacheTradingModel
from trade_engine.model.classic.TradingRulesModel                    import TradingRulesModel
from trade_engine.model.classic.VotingTradingRulesModel              import VotingTradingRulesModel
from trade_engine.exit_ts.TradeExitStack                             import TradeExitStack
from trade_engine.enter_ts.TradeEnterStack                           import TradeEnterStack
from trade_engine.investment_manager.PortfolioInvMng                 import PortfolioInvMng
from trade_engine.investment_manager.PortfolioRebalanceFrequency     import PortfolioRebalanceFrequency
from trade_engine.registry.PortfolioRegisterItem                     import PortfolioRegisterItem
from trade_engine.model.ai.LSTM_Model                                import LSTM_Model
from trade_engine.model.ai.WaveNet_RNN_AI_TradingModel               import WaveNet_RNN_AI_TradingModel
from trade_engine.model.ai.WaveNet_RNN_AI_TradingModel               import WaveNet_RNN_AI_Trading_Rules
from trade_engine.model.ai.WaveNet_RNN_AI_PipelineBuilder            import WaveNet_RNN_AI_PipelineBuilder
from trade_engine.enter_ts.TradeEnterAIStrategy                      import TradeEnterAIStrategy
from trade_engine.exit_ts.TradeExitAIStrategy                        import TradeExitAIStrategy
from trade_engine.ts_actions.policy.TradeEnterSetPolicy  import TradeEnterSetPolicy, TradeEnterSetVotingPolicy
from trade_engine.ts_actions.policy.TradeEnterPolicy     import TradeEnterPolicy
from trade_engine.ts_actions.policy.TradeExitSetPolicy   import TradeExitSetPolicy, TradeExitSetVotingPolicy
from trade_engine.ts_actions.policy.TradeExitPolicy      import TradeExitPolicy

# *** Additional Imports required for running WFA Backtest and Slide Win WFA Backtest

from trade_engine.execution.BacktestExecutionWFA             import BacktestExecutionWFA, WFASlideWindowPeriod
from trade_engine.execution.BacktestExecutionSlideWindowWFA  import BacktestExecutionSlideWindowWFA
from trade_engine.execution.BacktestExecutionSlideWindowWFA  import WFASlideWinScenarioFixDatasets
from trade_engine.execution.BacktestExecutionSlideWindowWFA  import WFASlideWinScenarioSlidingDatasets
from trade_engine.execution.BacktestExecutionSlideWindowWFA  import WFASlideWinScenarioAnchoredSlidingDatasets

# For other examples
from trade_engine.investment_manager.TradeFeePolicy          import TradeFeePolicy, TradeFeeType

Trade Strategies

Nasdaq ETF - Yahoo Finance Market Data - SMA Trade Strategy

  • SMA Trade Strategy for Nasdaq ETF

    Description:

      1. $2.0M Budget
      2. 100% capital invested
    
    

    Trade Strategies:

      1. One trade strategy: Nasdaq using Simple Moving Average(SMA) for entering/exiting a trade
    
    

    Backtest:

      1. Type: regular
      2. Test Period: 
          1. Begin Date = 2001-01-01 
          2. End Date   = 2005-12-31 
Trade Asset
In [67]:
trade_asset   = "^IXIC" 
Market Data Manager

Market Data Manager configured to use yahoo-finance for obtaining market data

The following TradeStrategyMarketDataMng object will do the following:

1. Download market data for: 
    [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
2. Used yahoo-finance as the market provider
3. Save the downloaded data in the directory and file specified by the arguments:
   1. dirPathMarketData
   2. fileNameMarketData
4. It will request the market data provider to get data from "beg_date_str" to "end_date_str"
5. If end_date_str is not defined (as the case below), all data available from the begin date is 
   requested.
6. Interval is set to "1d", this parameter is market data provider specific, see Yahoo-Finance, 
   Quandal for what options they support
7. The **Adj Close** column is configured as the default price column 
8. Note that even so leveraged ETFs are requested from 2000-01-01 to the present, the data 
   actually returned for these stock symbols by Yahoo-Finance doesn't start until 2011.
   The behavior is market data provider specific
In [68]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        forceCreateMarketData  = False,
        interval               = "1d"  ) 
In [69]:
ts_marketdat_mng.marketDataObj.getDataFrame()
Out[69]:
Index Adj Close Close High Low Open Volume Next_Period_Open Next_Date
Date
2000-01-03 ^DJI 11357.509766 11357.509766 11522.009766 11305.690430 11501.849609 169750000 11349.750000 2000-01-04
2000-01-04 ^DJI 10997.929688 10997.929688 11350.059570 10986.450195 11349.750000 178420000 10989.370117 2000-01-05
2000-01-05 ^DJI 11122.650391 11122.650391 11215.099609 10938.669922 10989.370117 203190000 11113.370117 2000-01-06
2000-01-06 ^DJI 11253.259766 11253.259766 11313.450195 11098.450195 11113.370117 176550000 11247.059570 2000-01-07
2000-01-07 ^DJI 11522.559570 11522.559570 11528.139648 11239.919922 11247.059570 184900000 11532.480469 2000-01-10
... ... ... ... ... ... ... ... ... ...
2021-12-02 SQQQ 6.490000 6.490000 6.780000 6.390000 6.710000 247502800 6.420000 2021-12-03
2021-12-03 SQQQ 6.820000 6.820000 7.040000 6.370000 6.420000 255982700 6.810000 2021-12-06
2021-12-06 SQQQ 6.660000 6.660000 7.030000 6.590000 6.810000 175486700 6.310000 2021-12-07
2021-12-07 SQQQ 6.050000 6.050000 6.320000 6.030000 6.310000 196456900 6.040000 2021-12-08
2021-12-08 SQQQ 5.980000 5.980000 6.140000 5.970000 6.040000 167700500 5.980000 2021-12-08

35053 rows × 9 columns

Simulation Broker
In [70]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Model
In [71]:
tsConfDat = TradeStrategyConfigData()

# SMA JSON Configuration
#
# Model Configuration:
#                win_fast   : fast moving average
#                win_slow   : slow moving average
# Signals to enter and exit a trade based on the fast ma crossing the slow ma

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } },
                            } } )
Trade Strategy, Trade Investment Manager, and Trade Asset Register Item
In [72]:
taRegItemGen = TradeAssetRegisterItemGenerator()

ts_registered_obj = taRegItemGen.createSingleTARegItem(
                           name_ta_reg_item        = "Nasdaq ETF Backtest",
    
                           # *** Trade Assets & Market Data
                           trade_asset             = trade_asset,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestment                          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                      )
Display Entry Rules Generated SMA Signals
In [73]:
print("Number of Enter Models: ", len(ts_registered_obj.getTradeStrategyModel().getTSEnterSetObj().tsEntries) )
Number of Enter Models:  1
In [74]:
ts_registered_obj.getTradeStrategyModel().getTSEnterSetObj().tsEntries[0].ts_model_pipline_mng.\
     getAllModelDataPipelineDataForStockSymbol(stockSymbol = "^IXIC" )
Out[74]:
Index Adj Close Close High Low Open Volume Next_Period_Open Next_Date sma_fast sma_slow sma_fast_gt_sma_slow sma_fast_lt_sma_slow
Date
2000-05-24 ^IXIC 3270.610107 3270.610107 3276.189941 3042.659912 3155.139893 2087980000 3308.510010 2000-05-25 3599.450500 4167.194609 0 1
2000-05-25 ^IXIC 3205.350098 3205.350098 3365.840088 3194.590088 3308.510010 1561840000 3215.280029 2000-05-26 3571.016504 4157.936611 0 1
2000-05-26 ^IXIC 3205.110107 3205.110107 3256.629883 3150.780029 3215.280029 1069440000 3286.540039 2000-05-30 3538.239014 4150.970813 0 1
2000-05-30 ^IXIC 3459.479980 3459.479980 3460.239990 3286.540039 3286.540039 1457360000 3428.250000 2000-05-31 3513.309009 4146.790212 0 1
2000-05-31 ^IXIC 3400.909912 3400.909912 3501.510010 3399.620117 3428.250000 1533730000 3471.949951 2000-06-01 3494.082007 4143.528013 0 1
... ... ... ... ... ... ... ... ... ... ... ... ... ...
2021-12-02 ^IXIC 15381.320312 15381.320312 15444.540039 15150.120117 15181.820312 5390100000 15428.709961 2021-12-03 15784.593066 15078.034492 1 0
2021-12-03 ^IXIC 15085.469727 15085.469727 15470.360352 14931.059570 15428.709961 5859520000 15117.629883 2021-12-06 15741.851074 15082.439688 1 0
2021-12-06 ^IXIC 15225.150391 15225.150391 15281.990234 14931.610352 15117.629883 5095960000 15510.910156 2021-12-07 15704.529102 15089.259893 1 0
2021-12-07 ^IXIC 15686.919922 15686.919922 15720.089844 15507.660156 15510.910156 5091220000 15690.650391 2021-12-08 15689.757080 15101.856689 1 0
2021-12-08 ^IXIC 15786.990234 15786.990234 15792.639648 15618.879883 15690.650391 4600800000 15786.990234 2021-12-08 15684.779590 15116.976787 1 0

5421 rows × 13 columns

Execute Backtest
In [75]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Nasdaq ETF - SMA Trade Strategy",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2001-01-01", 
                                            strEndDate = "2005-12-31" ),
                    trade_asset_registered_item = ts_registered_obj )
In [76]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-02-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-02-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-07 00:00:00 
****************

Backtest Metrics
Save to Excel
In [77]:
tsExecuteEngine.getSummaryMetrics().to_excel("Nasdaq ETF SMA Model backtest-metrics.xlsx")
Execution & Investment Metrics
In [78]:
tsExecuteEngine.getExecutionMetrics()
Out[78]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 ts_sma_^IXIC None None None No 0 22 2000000.0 1.630618e+06 0.0 -0.184691 Completed
Performance Metrics
In [79]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[79]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 ts_sma_^IXIC No Static ^IXIC 2001-01-03 2005-12-30 1.0 -0.17 -0.04 -0.02 -0.49 0.08 -0.15
Persist Backtest to DB (optional )
In [80]:
session.add( tsExecuteEngine )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst)
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done

Cottons Futures - Quandal Market Data - SMA Trade Strategy

  • SMA Trade Strategy for Cottons Future

    Description:

      1. $2.0M Budget
      2. 100% capital invested
    
    

    Trade Strategies:

      1. One trade strategy: Cotton's Futures using Simple Moving Average(SMA) for entering/exiting a trade
    
    

    Backtest:

      1. Type: regular
      2. Test Period: 
          1. Begin Date = 2002-01-01 
          2. End Date   = 2005-12-31 
Trade Asset
In [33]:
trade_asset = "CHRIS/ICE_CT1"
Market Data Manager
Trade Assets - Quandal

Download the following data from Quandal:

  1. CHRIS/ICE_CT1

    Where CHRIS is the Quandal Data Provider, and the name after the / is the Futures symbol.

    The format of the JSON to download from Quandal is:

    { quandal-path :

       [ description of data, 
         [ columns to extract from the returned Quandal DataFrame ], 
         { "Quandal_Column" : "Rename Quandal Column" } 
       ]
    

    }

Note:

1. The nested dictionary to rename the original downloaded Quandal data, it is provided since Quandal does
   not have standard output column names.  
       - Futures data from different data sources might have different returned column names for the same
         state, that is "Close" vs. "close", etc.
       - For sharing the same market data manager object it is recommended to rename the columns to have 
         standard names, and match the ones provided by Yahoo Finance

2. Yahoo Finance returns standard equity column names

3. All implemented AI and Technical Models used standard column names (same as Yahoo Finance)
   Columns: Adj Close, Close, Open, High, Low, Volume
   Index: Datetime

4. In order to use the implemented models the Quandal Market Data or any Custom Market Data must have
   similar named columns, or the user can implement his own models and use whatever column names he/she
   prefers.

5. In this example, the Quandal data source does not provide all standard column names, only open,
   which is re-named to 'Adj Close'.  Therefore only some of the built models will be available,
   as they required High, Low, such as Bollinger Bands
In [35]:
indexQuantCodeMap = { 
       "CHRIS/ICE_CT1" : ["Cotton",   ["Open", "Volume"],  { "Open" : "Adj Close" } ] 
}
In [39]:
dirPathMarketDataQuandl = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/TSMarketDat'

beg_date_for_feature_creation = "2000-10-01"
beg_date_str                  = "2001-01-01"
end_date_str                  = "2010-12-31"

q_stock_index_list = list ( indexQuantCodeMap.keys()  )

ts_marketdat_mng_quandal = TradeStrategyMarketDataMng(\
        marketDataProviderName = "quandl",
        supportedTradeAssets   = q_stock_index_list,   
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "Quandl_Test_1",
        dirPathMarketData      = dirPathMarketDataQuandl,
        beg_date_str           = beg_date_for_feature_creation,
        end_date_str           = end_date_str,
        interval               = "1d" ,
        updateDataPassEndDate  = False,
        forceCreateMarketData  = True,
        indexQuantCodeMap      = indexQuantCodeMap,     # required for quandl market data provider, defined above
        # The Quandal provider used does not return Open, High, Low, Close, so map the "Adj Close" column
        # to all standard columns in order to utilized some of the models that required that data (ATR, etc.)
        create_std_ohlc_cols_dict = { "Open" : "Adj Close", "Low" : "Adj Close",
                                      "High" : "Adj Close", "Close" : "Adj Close" }
        ) 
******* Initial Market Data Download ******* 

Downloading: ['CHRIS/ICE_CT1'] interval = daily  beg_date = 2000-10-01  end_date = 2010-12-31
In [40]:
ts_marketdat_mng_quandal.marketDataObj.getDataFrame()
Out[40]:
Index Index_Name Provider Adj Close Volume Open Low High Close Next_Period_Open Next_Date
Date
2000-10-02 CHRIS/ICE_CT1 Cotton Quandl 62.17 40.0 62.17 62.17 62.17 62.17 63.40 2000-10-03
2000-10-03 CHRIS/ICE_CT1 Cotton Quandl 63.40 120.0 63.40 63.40 63.40 63.40 63.70 2000-10-04
2000-10-04 CHRIS/ICE_CT1 Cotton Quandl 63.70 37.0 63.70 63.70 63.70 63.70 63.80 2000-10-05
2000-10-05 CHRIS/ICE_CT1 Cotton Quandl 63.80 21.0 63.80 63.80 63.80 63.80 63.95 2000-10-06
2000-10-06 CHRIS/ICE_CT1 Cotton Quandl 63.95 84.0 63.95 63.95 63.95 63.95 64.10 2000-10-09
... ... ... ... ... ... ... ... ... ... ... ...
2010-12-27 CHRIS/ICE_CT1 Cotton Quandl 147.12 7893.0 147.12 147.12 147.12 147.12 146.31 2010-12-28
2010-12-28 CHRIS/ICE_CT1 Cotton Quandl 146.31 4413.0 146.31 146.31 146.31 146.31 143.86 2010-12-29
2010-12-29 CHRIS/ICE_CT1 Cotton Quandl 143.86 6900.0 143.86 143.86 143.86 143.86 140.00 2010-12-30
2010-12-30 CHRIS/ICE_CT1 Cotton Quandl 140.00 10309.0 140.00 140.00 140.00 140.00 144.00 2010-12-31
2010-12-31 CHRIS/ICE_CT1 Cotton Quandl 144.00 5421.0 144.00 144.00 144.00 144.00 144.00 2010-12-31

2401 rows × 11 columns

Simulation Broker
In [41]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Model
In [42]:
tsConfDat = TradeStrategyConfigData()

# SMA JSON Configuration

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } },
                            } } )
Trade Strategy, Trade Investment Manager, and Trade Asset Register Item
In [44]:
taRegItemGen = TradeAssetRegisterItemGenerator()

ts_registered_obj = taRegItemGen.createSingleTARegItem(
                           name_ta_reg_item        = "Cotton Futures Backtest",
    
                           # *** Trade Assets & Market Data
                           trade_asset             = trade_asset,
                           ts_marketdat_mng        = ts_marketdat_mng_quandal,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestment                          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                      )
Display Entry Rules Generated SMA Signals
In [46]:
ts_registered_obj.getTradeStrategyModel().getTSEnterSetObj().tsEntries[0].ts_model_pipline_mng.\
     getAllModelDataPipelineDataForStockSymbol(stockSymbol = trade_asset )
Out[46]:
Index Index_Name Provider Adj Close Volume Open Low High Close Next_Period_Open Next_Date sma_fast sma_slow sma_fast_gt_sma_slow sma_fast_lt_sma_slow
Date
2001-02-26 CHRIS/ICE_CT1 Cotton Quandl 55.25 49.0 55.25 55.25 55.25 55.25 53.50 2001-02-27 59.3340 62.6098 0 1
2001-02-27 CHRIS/ICE_CT1 Cotton Quandl 53.50 176.0 53.50 53.50 53.50 53.50 51.95 2001-02-28 58.9390 62.5231 0 1
2001-02-28 CHRIS/ICE_CT1 Cotton Quandl 51.95 166.0 51.95 51.95 51.95 51.95 53.10 2001-03-01 58.4860 62.4086 0 1
2001-03-01 CHRIS/ICE_CT1 Cotton Quandl 53.10 46.0 53.10 53.10 53.10 53.10 53.75 2001-03-02 58.0310 62.3026 0 1
2001-03-02 CHRIS/ICE_CT1 Cotton Quandl 53.75 83.0 53.75 53.75 53.75 53.75 54.50 2001-03-05 57.6685 62.2021 0 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2010-12-27 CHRIS/ICE_CT1 Cotton Quandl 147.12 7893.0 147.12 147.12 147.12 147.12 146.31 2010-12-28 136.7070 108.9030 1 0
2010-12-28 CHRIS/ICE_CT1 Cotton Quandl 146.31 4413.0 146.31 146.31 146.31 146.31 143.86 2010-12-29 137.5775 109.5818 1 0
2010-12-29 CHRIS/ICE_CT1 Cotton Quandl 143.86 6900.0 143.86 143.86 143.86 143.86 140.00 2010-12-30 138.0755 110.2359 1 0
2010-12-30 CHRIS/ICE_CT1 Cotton Quandl 140.00 10309.0 140.00 140.00 140.00 140.00 144.00 2010-12-31 138.7005 110.8444 1 0
2010-12-31 CHRIS/ICE_CT1 Cotton Quandl 144.00 5421.0 144.00 144.00 144.00 144.00 144.00 2010-12-31 139.8280 111.4864 1 0

2302 rows × 15 columns

Execute Backtest
In [47]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Cottons Futures - SMA Trade Strategy",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2002-01-01", 
                                            strEndDate = "2005-12-31" ),
                    trade_asset_registered_item = ts_registered_obj )
In [48]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-02-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-02-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-23 00:00:00 
****************

Backtest Metrics
Save to Excel
In [49]:
tsExecuteEngine.getSummaryMetrics().to_excel("Cottons Futures backtest-metrics.xlsx")
Execution & Investment Metrics
In [50]:
tsExecuteEngine.getExecutionMetrics()
Out[50]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 ts_sma_CHRIS/ICE_CT1 None None None No 0 13 2000000.0 1498444.49 0.0 -0.250778 Completed
Performance Metrics
In [51]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[51]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 ts_sma_CHRIS/ICE_CT1 No Static CHRIS/ICE_CT1 2002-01-03 2005-12-30 0.98 -0.22 -0.06 -0.01 -0.41 0.19 -0.09
Persist Backtest to DB (optional )
In [52]:
session.add( tsExecuteEngine )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst)
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done

Nasdaq ETF - Yahoo Finance Market Data - LSTM Trade Strategy

  • LSTM Trade Strategy for Nasdaq ETF

    Description:

      1. $2.0M Budget
      2. 100% capital invested
    
    

    Trade Strategies:

      1. One trade strategy: Nasdaq using a LSTM-Model for entering/exiting a trade
    
    

    Backtest:

      1. Type: regular
      2. AI Models Fit Date Ranges
          1. Training Period: 
              1. Begin Date = 2001-01-01 
              2. End Date   = 2005-12-31  
          2. Validation Period: 
              1. Begin Date = 2006-01-01 
              2. End Date   = 2007-12-31   
      4. Test Period: 
          1. Begin Date = 2008-01-01 
          2. End Date   = 2008-12-31 
Trade Asset
In [53]:
trade_asset   =  "^IXIC" 
Market Data Manager

Market Data Manager configured to use yahoo-finance for obtaining market data

The following TradeStrategyMarketDataMng object will do the following:

1. Download market data for: 
    [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
2. Used yahoo-finance as the market provider
3. Save the downloaded data in the directory and file specified by the arguments:
   1. dirPathMarketData
   2. fileNameMarketData
4. It will request the market data provider to get data from "beg_date_str" to "end_date_str"
5. If end_date_str is not defined (as the case below), all data available from the begin date is 
   requested.
6. Interval is set to "1d", this parameter is market data provider specific, see Yahoo-Finance, 
   Quandal for what options they support
7. The **Adj Close** column is configured as the default price column 
8. Note that even so leveraged ETFs are requested from 2000-01-01 to the present, the data 
   actually returned for these stock symbols by Yahoo-Finance doesn't start until 2011.
   The behavior is market data provider specific
In [54]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
In [55]:
ts_marketdat_mng.marketDataObj.getDataFrame()
Out[55]:
Index Adj Close Close High Low Open Volume Next_Period_Open Next_Date
Date
2000-01-03 ^DJI 11357.509766 11357.509766 11522.009766 11305.690430 11501.849609 169750000 11349.750000 2000-01-04
2000-01-04 ^DJI 10997.929688 10997.929688 11350.059570 10986.450195 11349.750000 178420000 10989.370117 2000-01-05
2000-01-05 ^DJI 11122.650391 11122.650391 11215.099609 10938.669922 10989.370117 203190000 11113.370117 2000-01-06
2000-01-06 ^DJI 11253.259766 11253.259766 11313.450195 11098.450195 11113.370117 176550000 11247.059570 2000-01-07
2000-01-07 ^DJI 11522.559570 11522.559570 11528.139648 11239.919922 11247.059570 184900000 11532.480469 2000-01-10
... ... ... ... ... ... ... ... ... ...
2021-12-02 SQQQ 6.490000 6.490000 6.780000 6.390000 6.710000 247502800 6.420000 2021-12-03
2021-12-03 SQQQ 6.820000 6.820000 7.040000 6.370000 6.420000 255982700 6.810000 2021-12-06
2021-12-06 SQQQ 6.660000 6.660000 7.030000 6.590000 6.810000 175486700 6.310000 2021-12-07
2021-12-07 SQQQ 6.050000 6.050000 6.320000 6.030000 6.310000 196456900 6.040000 2021-12-08
2021-12-08 SQQQ 5.980000 5.980000 6.140000 5.970000 6.040000 167700500 5.980000 2021-12-08

35053 rows × 9 columns

Simulation Broker
In [56]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Model
In [57]:
tsConfDat = TradeStrategyConfigData()

# LSTM JSON Configuration
#
# Model configuration:
#     Simple LSTM MOdel with two layers
#     n_steps            : length of time series
#     no_neurons_lay1    : layer 1 neurons
#     no_neurons_lay2    : layer 2 neurons
#     pred_ahead_periods : Number of prediction points ahead
#     epochs             : Number of epochs
#     ext_trade_dyn      : Extend an existent trade dymically based on current period predictions
#     re_eval_exit_dyn   : Re-evaluate exiting a trade dynamically based on current period predictions
#     entry_policy_args  :
#                          lastn_match        : Enter a trade if the last n predictions matched
#                          cross_enter_signal : Enter a trade if the there is a cross-over signal, 
#                                               from buy-to-sell, sell-to-buy
#     exit_policy_args   :
#                          lastn_match        : Exit a trade if the last n predictions matched


tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )
Trade Strategy, Trade Investment Manager, and Trade Asset Register Item
In [58]:
taRegItemGen = TradeAssetRegisterItemGenerator()

ts_registered_obj = taRegItemGen.createSingleTARegItem(
                           name_ta_reg_item        = "Nasdaq ETF -LSTM Model- Backtest",
    
                           # *** Trade Assets & Market Data
                           trade_asset             = trade_asset,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestment                          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                      )
Display Pipeline Data for LSTM Model
In [59]:
# Pipeline just normalizes the data for LSTM Model

ts_registered_obj.getTradeStrategyModel().getTSEnterSetObj().tsEntries[0].ts_model_pipline_mng.\
     getAllModelDataPipelineDataForStockSymbol(stockSymbol = "^IXIC" )
Out[59]:
Adj Close Close High Low Open Volume Index
Date
2000-01-03 0.201899 0.201899 0.202722 0.193257 0.204572 0.124230 ^IXIC
2000-01-04 0.186543 0.186543 0.194832 0.187121 0.193496 0.124392 ^IXIC
2000-01-05 0.184927 0.184927 0.184947 0.176164 0.182455 0.144828 ^IXIC
2000-01-06 0.174862 0.174862 0.181269 0.174873 0.181128 0.132287 ^IXIC
2000-01-07 0.185267 0.185267 0.182191 0.174569 0.172907 0.135630 ^IXIC
... ... ... ... ... ... ... ...
2021-12-02 0.954754 0.954754 0.949080 0.941839 0.937411 0.478482 ^IXIC
2021-12-03 0.934956 0.934956 0.950792 0.927145 0.953865 0.521340 ^IXIC
2021-12-06 0.944304 0.944304 0.938298 0.927182 0.933133 0.451626 ^IXIC
2021-12-07 0.975205 0.975205 0.967357 0.965821 0.959344 0.451194 ^IXIC
2021-12-08 0.981902 0.981902 0.972169 0.973281 0.971323 0.406418 ^IXIC

5520 rows × 7 columns

Training, Validation and Test Periods for Backtest

In Order to backtest a trade strategy or portfolio that has AI models, the following data is required:

  1. Training Date Range

    1. Date range that will be used to train the AI models in the backtest
  2. Validation Date Range

    1. Date range that twill be used to validate the AI models
  3. Test Period Date Range
    1. This is the out-sample date range, which corresponds to the date range of the backtest

Date Ranges are defined with a DatasetDef object, and have the following parameters:

  1. strBegDateAIModels : Date to begin training or validation of an AI model
  2. strBegDate : Date to begin the backtest
  3. strEndDate : Date to end training, validation and Backtest

Note:

  1. The param strBegDateAIModels can be defined as the same date as strBegDate, that is the default, if not defined.
  2. The critical aspect of using this parameter is in the backtest. Some AI Models, such as time series, others using moving averages over many periods, create params with no predicting data for those initial dates. Thus, in order to ensure the backtest starts on the actual date specified, the strBegDateAIModels should be defined as an earlier date, and it should not overlapped with the validation period end-date to avoid any chance of bias by picking at the validation data.
In [60]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2000-07-01",
                             strBegDate         = "2001-01-01",
                             strEndDate         = "2005-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2005-07-01",
                               strBegDate         = "2006-01-01",
                               strEndDate         = "2007-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2007-07-01",
                               strBegDate         = "2008-01-01",
                               strEndDate         = "2008-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
Execute Backtest
In [61]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Nasdaq-ETF LSTM based Trade Strategy",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = ts_registered_obj )
In [62]:
tsExecuteEngine.evaluate()
**** Fitting Model:  LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

Backtest Metrics
Save to Excel
In [66]:
tsExecuteEngine.getSummaryMetrics().to_excel("Nasdaq ETF LSTM Model backtest-metrics.xlsx")
Execution & Investment Metrics
In [63]:
tsExecuteEngine.getExecutionMetrics()
Out[63]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 ts_lstm_^IXIC None None None No 0 53 2000000.0 3.529230e+06 0.0 0.764615 Completed
Performance Metrics
In [64]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[64]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 ts_lstm_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.76 0.77 1.59 -0.21 0.12 -0.07
Persist Backtest to DB (optional )
In [65]:
session.add( tsExecuteEngine )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst)
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done

Portfolios

Portfolio A

  1. Portfolio A: Long and SMA Trade Strategies for US Indixes

    Description:

     1. Portfolio with 6 trading strategies
     2. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Trade Strategies:

     1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold
     2. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using SMA 
    
    

    Backtest:

     1. Type: regular
     2. Test Period: 
         1. Begin Date = 2001-01-01 
         2. End Date = 2001-12-31 
Portfolio Trade Assets
In [7]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [8]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
In [9]:
ts_marketdat_mng.marketDataObj.getDataFrame().query('Index == "^DJI" ')
Out[9]:
Index Adj Close Close High Low Open Volume Next_Period_Open Next_Date
Date
2000-01-03 ^DJI 11357.509766 11357.509766 11522.009766 11305.690430 11501.849609 169750000 11349.750000 2000-01-04
2000-01-04 ^DJI 10997.929688 10997.929688 11350.059570 10986.450195 11349.750000 178420000 10989.370117 2000-01-05
2000-01-05 ^DJI 11122.650391 11122.650391 11215.099609 10938.669922 10989.370117 203190000 11113.370117 2000-01-06
2000-01-06 ^DJI 11253.259766 11253.259766 11313.450195 11098.450195 11113.370117 176550000 11247.059570 2000-01-07
2000-01-07 ^DJI 11522.559570 11522.559570 11528.139648 11239.919922 11247.059570 184900000 11532.480469 2000-01-10
... ... ... ... ... ... ... ... ... ...
2021-12-02 ^DJI 34639.789062 34639.789062 34759.648438 34076.250000 34076.250000 466900000 34692.781250 2021-12-03
2021-12-03 ^DJI 34580.078125 34580.078125 34801.308594 34264.570312 34692.781250 439550000 34633.429688 2021-12-06
2021-12-06 ^DJI 35227.031250 35227.031250 35356.750000 34633.429688 34633.429688 416720000 35423.988281 2021-12-07
2021-12-07 ^DJI 35719.429688 35719.429688 35819.468750 35423.988281 35423.988281 474940000 35716.851562 2021-12-08
2021-12-08 ^DJI 35754.750000 35754.750000 35840.519531 35602.648438 35716.851562 387650000 35754.750000 2021-12-08

5520 rows × 9 columns

Enter & Exit Models
In [10]:
tsConfDat = TradeStrategyConfigData()

# Model Params
         
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 2 } },
                             },
                    }  )
Simulation Broker
In [11]:
brokerTradingObj = SimBrokerTrading()
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [12]:
    
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio A",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
Persist to DB (optional)
In [13]:
session.add( portf_registered_obj )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done
Re-Store from DB (optional)
In [14]:
session.expunge_all()
del portf_registered_obj

for tsObj in session.query(PortfolioRegisterItem):  
    print(tsObj.name)
    if  tsObj.name  == "Portfolio A" :
        break

portf_registered_obj = tsObj
print(portf_registered_obj.id, portf_registered_obj.name)
Portfolio A
1 Portfolio A
Execute Backtest
In [15]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio A",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2001-01-01", 
                                            strEndDate = "2001-12-31" ),
                    trade_asset_registered_item = portf_registered_obj )
In [16]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************

Backtest Metrics
Save to Excel
In [17]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-A backtest-metrics.xlsx")
Execution & Investment Metrics
In [18]:
tsExecuteEngine.getExecutionMetrics()
Out[18]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 Portfolio A 1 1 NaN Yes 0 22 12000000.0 1.219009e+07 0.0 0.015841 Completed
1 ts_sma_1_^DJI 1 1 1.0 No 0 7 2000000.0 2.168469e+06 0.0 0.084235 Completed
2 ts_sma_1_^IXIC 2 2 1.0 No 0 6 2000000.0 2.438655e+06 0.0 0.219327 Completed
3 ts_sma_1_^GSPC 3 3 1.0 No 0 6 2000000.0 2.208141e+06 0.0 0.104071 Completed
4 Long-Only Trade Strategy for ^DJI 4 4 1.0 No 0 1 2000000.0 1.883204e+06 0.0 -0.058398 Completed
5 Long-Only Trade Strategy for ^IXIC 5 5 1.0 No 0 1 2000000.0 1.702247e+06 0.0 -0.148877 Completed
6 Long-Only Trade Strategy for ^GSPC 6 6 1.0 No 0 1 2000000.0 1.789374e+06 0.0 -0.105313 Completed
Performance Metrics
In [19]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[19]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio A Yes 2001-01-03 2001-12-31 1.0 0.02 0.02 0.19 -0.09 0.04 -0.02
1 ts_sma_1_^DJI No Static ^DJI 2001-01-03 2001-12-31 1.0 0.08 0.08 0.53 -0.12 0.06 -0.04
2 ts_sma_1_^IXIC No Static ^IXIC 2001-01-03 2001-12-31 1.0 0.22 0.22 0.77 -0.24 0.06 -0.05
3 ts_sma_1_^GSPC No Static ^GSPC 2001-01-03 2001-12-31 1.0 0.1 0.1 0.65 -0.11 0.04 -0.03
4 Long-Only Trade Strategy for ^DJI No Static ^DJI 2001-01-03 2001-12-31 1.0 -0.06 -0.06 -0.18 -0.27 0.04 -0.07
5 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2001-01-03 2001-12-31 1.0 -0.15 -0.15 -0.17 -0.5 0.14 -0.07
6 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2001-01-03 2001-12-31 1.0 -0.11 -0.11 -0.42 -0.3 0.05 -0.05
Persist Backtest to DB (optional )
In [20]:
session.add( tsExecuteEngine )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst)
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done
Re-Store Backtest
In [21]:
session.expunge_all()
del tsExecuteEngine

for tsObj in session.query(BacktestExecution):  
    print(tsObj.name)
    if  tsObj.name  == "Backtest for SMA based Trade Strategies" :
        break

tsExecuteEngine = tsObj
print(tsExecuteEngine.id, tsExecuteEngine.name)
Backtest for Portfolio A
1 Backtest for Portfolio A
In [22]:
tsExecuteEngine.getExecutionMetrics()
Out[22]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 Portfolio A 1 1 NaN Yes 0 22 12000000.0 1.219009e+07 0.0 0.015841 Completed
1 ts_sma_1_^DJI 1 1 1.0 No 0 7 2000000.0 2.168469e+06 0.0 0.084235 Completed
2 ts_sma_1_^IXIC 2 2 1.0 No 0 6 2000000.0 2.438655e+06 0.0 0.219327 Completed
3 ts_sma_1_^GSPC 3 3 1.0 No 0 6 2000000.0 2.208141e+06 0.0 0.104071 Completed
4 Long-Only Trade Strategy for ^DJI 4 4 1.0 No 0 1 2000000.0 1.883204e+06 0.0 -0.058398 Completed
5 Long-Only Trade Strategy for ^IXIC 5 5 1.0 No 0 1 2000000.0 1.702247e+06 0.0 -0.148877 Completed
6 Long-Only Trade Strategy for ^GSPC 6 6 1.0 No 0 1 2000000.0 1.789374e+06 0.0 -0.105313 Completed

Portfolio B

Portfolio B: Long and AI LSTM based Strategies for US Indixes

Description:

1. Portfolio with 6 trading strategies
2. $2,000,000/strategy
3. No-Rebalance during the backtest 
4. 100% capital invested
5. Portfolio investment using equal weights for each trade strategy

Trade Strategies:

1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold
2. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using LSTM AI Model 

Backtest:

1. Type: regular
2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2001-01-01 
        2. End Date   = 2005-12-31  
    2. Validation Period: 
        1. Begin Date = 2006-01-01 
        2. End Date   = 2007-12-31   
4. Test Period: 
    1. Begin Date = 2008-01-01 
    2. End Date   = 2008-12-31 
Portfolio Trade Assets
In [23]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [24]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Enter & Exit Models
In [25]:
tsConfDat = TradeStrategyConfigData()

# Model Params

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
Simulation Broker
In [26]:
brokerTradingObj = SimBrokerTrading()
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [27]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio B",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
Persist to DB (optional)
In [28]:
session.add( portf_registered_obj )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done
Re-Store from DB (optional)
In [29]:
session.expunge_all()
del portf_registered_obj

for tsObj in session.query(PortfolioRegisterItem):  
    if  tsObj.name  == "Portfolio B" :
        break

portf_registered_obj = tsObj
print(portf_registered_obj.id, portf_registered_obj.name)
2 Portfolio B
Training, Validation and Test Periods for Backtest
In [30]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2000-07-01",
                             strBegDate         = "2001-01-01",
                             strEndDate         = "2005-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2005-07-01",
                               strBegDate         = "2006-01-01",
                               strEndDate         = "2007-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2007-07-01",
                               strBegDate         = "2008-01-01",
                               strEndDate         = "2008-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
Execute Backtest
In [31]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio B",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [32]:
tsExecuteEngine.evaluate()
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

Backtest Metrics
Save to Excel
In [33]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-B backtest-metrics.xlsx")
Execution & Investment Metrics
In [34]:
tsExecuteEngine.getExecutionMetrics()
Out[34]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 Portfolio B 2 2 NaN Yes 0 125 12000000.0 1.639691e+07 0.0 0.366409 Completed
1 ts_lstm_^DJI 7 7 2.0 No 0 47 2000000.0 4.708130e+06 0.0 1.354065 Completed
2 ts_lstm_^IXIC 8 8 2.0 No 0 53 2000000.0 3.529230e+06 0.0 0.764615 Completed
3 ts_lstm_^GSPC 9 9 2.0 No 0 22 2000000.0 4.355144e+06 0.0 1.177572 Completed
4 Long-Only Trade Strategy for ^DJI 10 10 2.0 No 0 1 2000000.0 1.347062e+06 0.0 -0.326469 Completed
5 Long-Only Trade Strategy for ^IXIC 11 11 2.0 No 0 1 2000000.0 1.209029e+06 0.0 -0.395486 Completed
6 Long-Only Trade Strategy for ^GSPC 12 12 2.0 No 0 1 2000000.0 1.248316e+06 0.0 -0.375842 Completed
Performance Metrics
In [35]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[35]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio B Yes 2008-01-03 2008-12-31 1.0 0.37 0.37 1.45 -0.14 0.11 -0.06
1 ts_lstm_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 1.35 1.37 2.45 -0.22 0.11 -0.07
2 ts_lstm_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.76 0.77 1.59 -0.21 0.12 -0.07
3 ts_lstm_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 1.18 1.19 2.25 -0.14 0.12 -0.09
4 Long-Only Trade Strategy for ^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 -0.33 -0.33 -0.86 -0.42 0.11 -0.08
5 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 -0.4 -0.4 -1.02 -0.49 0.12 -0.09
6 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 -0.38 -0.38 -0.94 -0.48 0.12 -0.09
Persist Backtest to DB (optional )
In [36]:
session.add( tsExecuteEngine )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done
Re-Store Backtest
In [37]:
session.expunge_all()
del tsExecuteEngine

for tsObj in session.query(BacktestExecution):  
    if  tsObj.name  == "Backtest for Portfolio B" :
        break

tsExecuteEngine = tsObj
print(tsExecuteEngine.id, tsExecuteEngine.name)
2 Backtest for Portfolio B
In [38]:
tsExecuteEngine.getExecutionMetrics()
Out[38]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 Portfolio B 2 2 NaN Yes 0 125 12000000.0 1.639691e+07 0.0 0.366409 Completed
1 ts_lstm_^DJI 7 7 2.0 No 0 47 2000000.0 4.708130e+06 0.0 1.354065 Completed
2 ts_lstm_^IXIC 8 8 2.0 No 0 53 2000000.0 3.529230e+06 0.0 0.764615 Completed
3 ts_lstm_^GSPC 9 9 2.0 No 0 22 2000000.0 4.355144e+06 0.0 1.177572 Completed
4 Long-Only Trade Strategy for ^DJI 10 10 2.0 No 0 1 2000000.0 1.347062e+06 0.0 -0.326469 Completed
5 Long-Only Trade Strategy for ^IXIC 11 11 2.0 No 0 1 2000000.0 1.209029e+06 0.0 -0.395486 Completed
6 Long-Only Trade Strategy for ^GSPC 12 12 2.0 No 0 1 2000000.0 1.248316e+06 0.0 -0.375842 Completed

Portfolio C

  1. Portfolio C: Long and Multiple Configured SMA Trade Strategies for US Indixes

    Description:

     1. Portfolio with 27 trading strategies
     2. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Trade Strategies:

     1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold
     2. 21 trade strategies: Nasdaq, S&P 500, and DOW Jones using following SMA Configuration:
    
        sma-conf fast_mav, slow_mav, enter_if_last_nmatch, enter_if_cross_over_sig, exit_if_last_nmatch
             1       20       100          2                    True                     2
             2       10        50          2                    True                     2
             3       10        50          2                    True                     1
             4       15        60          2                    True                     2
             5       15        75          2                    True                     1
             6        7        35          2                    True                     2
             7        7        35          2                    True                     1               
    
     3. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using the following configuration: 
    
         - A Composite SMA Trade Strategy based on the the first five SMA Configured trade strategies
           above
    
         - The Set Entry cofiguration rules are: 
           a. Majority Voting (default)
              Three of the Five SMA Indicators configured in the set must signaled the same type of
              investment decision.
           b. Enter a trade if the last n voting decisions are the same, set to 1 (default )
           c. Enter a trade if there is cross-over signaled after applying rules a) and b), 
              set to False (default)
    
         - The Set Exit configuration rules are: 
           a. Majority Voting (Default)
               - Exit a long trade if the percent of SMA Indicators signaling an exit for a long position
                  is greater that the percent signaling no-exit 
               - Exit a short trade if the percent of SMA Indicators signaling an exit for a short position
                  is greater that the percent signaling no-exit 
           b. Exit a trade if the last n exit decisions are the same, set to 1 (default )
    
     4. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using the following configuration: 
    
         - A Composite SMA Trade Strategy based on all the SMA Configured trade strategies
    
         - The Set Entry cofiguration rules are: 
           a. Voting Percent
              The majority of the signals indicating an investment position (either short or long), 
              must also meet a minimum percent of 50% across all the strategies in the set.
           b. Enter a trade if the last n voting decisions are the same, set to 1 (default )
           c. Enter a trade if there is cross-over signaled after applying rules a) and b), 
              set to False (default)
    
         - The Set Exit configuration rules are: 
           a. Majority Voting (Default)
               - Exit a long trade if the percent of SMA Indicators signaling an exit for a long position
                  is greater that the percent signaling no-exit 
               - Exit a short trade if the percent of SMA Indicators signaling an exit for a short position
                  is greater that the percent signaling no-exit 
           b. Exit a trade if the last n exit decisions are the same, set to 1 (default )
    
    

    Backtest:

     1. Type: regular
     2. Test Period: 
         1. Begin Date = 2001-01-01 
         2. End Date   = 2001-12-31 
Portfolio Trade Assets
In [39]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [40]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [41]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [42]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #3

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_3",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_4",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_5",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 75 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_6",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_7",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )
Trade Strategies, Trade Inv. Manager, and Trade Asset Regiter Items
In [43]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio C",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [44]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  27
Execute Backtest
In [45]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio C",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2001-01-01", 
                                            strEndDate = "2001-12-31" ),
                    trade_asset_registered_item = portf_registered_obj )
In [46]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************

Backtest Metrics
Save To Excel
In [47]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-C backtest-metrics.xlsx")
Execution & Investment Metrics
In [48]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']]
Out[48]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
0 Portfolio C Yes 164 54000000.0 5.478234e+07 0.014488 Completed
1 ts_sma_1_^DJI No 6 2000000.0 1.865907e+06 -0.067047 Completed
2 ts_sma_2_^DJI No 7 2000000.0 2.338277e+06 0.169138 Completed
3 ts_sma_3_^DJI No 7 2000000.0 2.216315e+06 0.108158 Completed
4 ts_sma_4_^DJI No 7 2000000.0 1.933735e+06 -0.033132 Completed
5 ts_sma_5_^DJI No 5 2000000.0 1.956397e+06 -0.021801 Completed
6 ts_sma_6_^DJI No 7 2000000.0 2.366501e+06 0.183250 Completed
7 ts_sma_7_^DJI No 7 2000000.0 2.366501e+06 0.183250 Completed
8 all_All_^DJI No 7 2000000.0 2.302585e+06 0.151292 Completed
9 ts_sma_1_^IXIC No 8 2000000.0 1.677348e+06 -0.161326 Completed
10 ts_sma_2_^IXIC No 6 2000000.0 1.984685e+06 -0.007657 Completed
11 ts_sma_3_^IXIC No 6 2000000.0 2.396086e+06 0.198043 Completed
12 ts_sma_4_^IXIC No 6 2000000.0 1.961185e+06 -0.019407 Completed
13 ts_sma_5_^IXIC No 6 2000000.0 1.914764e+06 -0.042618 Completed
14 ts_sma_6_^IXIC No 8 2000000.0 1.736114e+06 -0.131943 Completed
15 ts_sma_7_^IXIC No 8 2000000.0 1.736114e+06 -0.131943 Completed
16 all_All_^IXIC No 6 2000000.0 1.997483e+06 -0.001258 Completed
17 ts_sma_1_^GSPC No 4 2000000.0 1.862138e+06 -0.068931 Completed
18 ts_sma_2_^GSPC No 6 2000000.0 2.191695e+06 0.095848 Completed
19 ts_sma_3_^GSPC No 6 2000000.0 2.256189e+06 0.128095 Completed
20 ts_sma_4_^GSPC No 6 2000000.0 1.798288e+06 -0.100856 Completed
21 ts_sma_5_^GSPC No 6 2000000.0 1.946798e+06 -0.026601 Completed
22 ts_sma_6_^GSPC No 10 2000000.0 2.229270e+06 0.114635 Completed
23 ts_sma_7_^GSPC No 10 2000000.0 2.229270e+06 0.114635 Completed
24 all_All_^GSPC No 6 2000000.0 2.143874e+06 0.071937 Completed
25 Long-Only Trade Strategy for ^DJI No 1 2000000.0 1.883204e+06 -0.058398 Completed
26 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 1.702247e+06 -0.148877 Completed
27 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 1.789374e+06 -0.105313 Completed
Performance Metrics
In [49]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[49]:
ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type exit_num_models exit_model exit_model_type stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio C Yes 0 0 2001-01-03 2001-12-31 0.02 0.02 0.2 -0.13 0.04 -0.04
1 ts_sma_1_^DJI No ^DJI Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.07 -0.07 -0.26 -0.2 0.06 -0.04
2 ts_sma_2_^DJI No ^DJI Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.17 0.17 0.93 -0.11 0.06 -0.04
3 ts_sma_3_^DJI No ^DJI Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.11 0.11 0.66 -0.11 0.06 -0.04
4 ts_sma_4_^DJI No ^DJI Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.03 -0.03 -0.09 -0.15 0.06 -0.04
5 ts_sma_5_^DJI No ^DJI Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.02 -0.02 -0.02 -0.18 0.06 -0.04
6 ts_sma_6_^DJI No ^DJI Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.18 0.18 0.98 -0.12 0.06 -0.04
7 ts_sma_7_^DJI No ^DJI Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.18 0.18 0.98 -0.12 0.06 -0.04
8 all_All_^DJI No ^DJI Market 7 composite 7 composite 2001-01-03 2001-12-31 0.15 0.15 0.85 -0.11 0.06 -0.04
9 ts_sma_1_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.15 -0.15 -0.2 -0.39 0.08 -0.15
10 ts_sma_2_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.01 0.01 0.22 -0.29 0.08 -0.15
11 ts_sma_3_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.2 0.2 0.72 -0.24 0.06 -0.05
12 ts_sma_4_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.0 -0.0 0.18 -0.25 0.08 -0.15
13 ts_sma_5_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.03 -0.03 0.14 -0.33 0.08 -0.15
14 ts_sma_6_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.12 -0.12 -0.14 -0.27 0.08 -0.15
15 ts_sma_7_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.12 -0.12 -0.14 -0.27 0.08 -0.15
16 all_All_^IXIC No ^IXIC Market 7 composite 7 composite 2001-01-03 2001-12-31 0.02 0.02 0.23 -0.26 0.08 -0.15
17 ts_sma_1_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.07 -0.07 -0.28 -0.24 0.04 -0.05
18 ts_sma_2_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.1 0.1 0.59 -0.11 0.04 -0.05
19 ts_sma_3_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.13 0.13 0.77 -0.11 0.04 -0.03
20 ts_sma_4_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.1 -0.1 -0.46 -0.2 0.04 -0.05
21 ts_sma_5_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 -0.03 -0.03 -0.05 -0.15 0.04 -0.05
22 ts_sma_6_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.11 0.12 0.67 -0.13 0.04 -0.05
23 ts_sma_7_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2001-01-03 2001-12-31 0.11 0.12 0.67 -0.13 0.04 -0.05
24 all_All_^GSPC No ^GSPC Market 7 composite 7 composite 2001-01-03 2001-12-31 0.07 0.07 0.47 -0.11 0.04 -0.05
25 Long-Only Trade Strategy for ^DJI No ^DJI Market None None None None None None 2001-01-03 2001-12-31 -0.06 -0.06 -0.18 -0.27 0.04 -0.07
26 Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None None None None 2001-01-03 2001-12-31 -0.15 -0.15 -0.17 -0.5 0.14 -0.07
27 Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None None None None 2001-01-03 2001-12-31 -0.11 -0.11 -0.42 -0.3 0.05 -0.05

Portfolio D

  1. Portfolio D: Long and Multiple Configured LSTM Trade Strategies for US Indixes

    Description:

     1. Portfolio with 27 trading strategies
     2. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Trade Strategies:

     1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold
     2. 21 trade strategies: Nasdaq, S&P 500, and DOW Jones using following LSTM Configurations:
    
                                                    LSTM Models
           Parameter                 #1      #2     #3       #4      #5      #6      #7
    
        epochs                       20      20     20       20      20      20      20
        no neurons layer 1           20      20     20       20      20      20      20
        no neurons layer 2           20      20     20       20      20      20      20
        time series length           20     100     50       50      40      30      60         
        no predictions ahead          3      15      5        5       3       3       5
        extend trade dyn            Yes     Yes    Yes      Yes     Yes     Yes     Yes
        re_evalaute_exit_dyn        Yes     Yes    Yes      Yes     Yes     Yes     Yes
        enter_if_last_nmatch          1       1      1        1       1       1       1
        enter_if_cross_over_sig      No      No     No       No      No      No      No
        exit_if_last_nmatch           1       1      1        2       1       1       1
    
     3. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using the following Composite 
        model configuration: 
    
         - A Composite LSTM Trade Strategy based on all the LSTM configured trade strategies above
    
         - The Set Entry cofiguration rules are: 
           a. Majority Voting (default)
           b. Enter a trade if the last n voting decisions are the same, set to 1 (default )
           c. Enter a trade if there is cross-over signaled after applying rules a) and b), 
              set to False (default)
    
         - The Set Exit configuration rules are: 
           a. Majority Voting (Default)
               - Exit a long trade if the percent of LSTM Indicators signaling an exit for a long position
                  is greater that the percent signaling no-exit 
               - Exit a short trade if the percent of LSTM Indicators signaling an exit for a short position
                  is greater that the percent signaling no-exit 
           b. Exit a trade if the last n exit decisions are the same, set to 1 (default )
    
    

    Backtest:

     1. Type: regular
     2. AI Models Fit Date Ranges
         1. Training Period: 
             1. Begin Date = 2001-01-01 
             2. End Date   = 2005-12-31  
         2. Validation Period: 
             1. Begin Date = 2006-01-01 
             2. End Date   = 2007-12-31   
     4. Test Period: 
         1. Begin Date = 2008-01-01 
         2. End Date   = 2008-12-31         
Portfolio Trade Assets
In [50]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [51]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [52]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [53]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm_2",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 100, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 15,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #3

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm_3",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm_4",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 2 } },
                             },
                    }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm_5",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 40, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm_6",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 30, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm_7",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 60, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 2 } },
                             },
                    }  )
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [54]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio D",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [55]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  27
Training, Validation and Test Periods for Backtest
In [56]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2000-07-01",
                             strBegDate         = "2001-01-01",
                             strEndDate         = "2005-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2005-07-01",
                               strBegDate         = "2006-01-01",
                               strEndDate         = "2007-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2007-07-01",
                               strBegDate         = "2008-01-01",
                               strEndDate         = "2008-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
Execute Backtest
In [57]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio D",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [58]:
tsExecuteEngine.evaluate()
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

Backtest Metrics
Save to Excel
In [59]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-D backtest-metrics.xlsx")
Execution & Investment Metrics
In [60]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']]
Out[60]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
0 Portfolio D Yes 852 54000000.0 9.456955e+07 0.751288 Completed
1 ts_lstm_1_^DJI No 47 2000000.0 4.708130e+06 1.354065 Completed
2 ts_lstm_2_^DJI No 47 2000000.0 4.708130e+06 1.354065 Completed
3 ts_lstm_3_^DJI No 47 2000000.0 4.708130e+06 1.354065 Completed
4 ts_lstm_4_^DJI No 23 2000000.0 2.378850e+06 0.189425 Completed
5 ts_lstm_5_^DJI No 47 2000000.0 4.708130e+06 1.354065 Completed
6 ts_lstm_6_^DJI No 31 2000000.0 3.337066e+06 0.668533 Completed
7 ts_lstm_7_^DJI No 23 2000000.0 2.378850e+06 0.189425 Completed
8 all_All_^DJI No 47 2000000.0 4.708130e+06 1.354065 Completed
9 ts_lstm_1_^IXIC No 53 2000000.0 3.529230e+06 0.764615 Completed
10 ts_lstm_2_^IXIC No 53 2000000.0 3.529230e+06 0.764615 Completed
11 ts_lstm_3_^IXIC No 53 2000000.0 3.529230e+06 0.764615 Completed
12 ts_lstm_4_^IXIC No 33 2000000.0 2.639077e+06 0.319539 Completed
13 ts_lstm_5_^IXIC No 53 2000000.0 3.529230e+06 0.764615 Completed
14 ts_lstm_6_^IXIC No 42 2000000.0 3.129032e+06 0.564516 Completed
15 ts_lstm_7_^IXIC No 33 2000000.0 2.639077e+06 0.319539 Completed
16 all_All_^IXIC No 53 2000000.0 3.529230e+06 0.764615 Completed
17 ts_lstm_1_^GSPC No 22 2000000.0 4.355144e+06 1.177572 Completed
18 ts_lstm_2_^GSPC No 22 2000000.0 4.355144e+06 1.177572 Completed
19 ts_lstm_3_^GSPC No 22 2000000.0 4.355144e+06 1.177572 Completed
20 ts_lstm_4_^GSPC No 16 2000000.0 3.676114e+06 0.838057 Completed
21 ts_lstm_5_^GSPC No 22 2000000.0 4.355144e+06 1.177572 Completed
22 ts_lstm_6_^GSPC No 22 2000000.0 3.948446e+06 0.974223 Completed
23 ts_lstm_7_^GSPC No 16 2000000.0 3.676114e+06 0.838057 Completed
24 all_All_^GSPC No 22 2000000.0 4.355144e+06 1.177572 Completed
25 Long-Only Trade Strategy for ^DJI No 1 2000000.0 1.347062e+06 -0.326469 Completed
26 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 1.209029e+06 -0.395486 Completed
27 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 1.248316e+06 -0.375842 Completed
Performance Metrics
In [61]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[61]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio D Yes 2008-01-03 2008-12-31 1.0 0.75 0.76 2.31 -0.11 0.11 -0.05
1 ts_lstm_1_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 1.35 1.37 2.45 -0.22 0.11 -0.07
2 ts_lstm_2_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 1.35 1.37 2.45 -0.22 0.11 -0.07
3 ts_lstm_3_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 1.35 1.37 2.45 -0.22 0.11 -0.07
4 ts_lstm_4_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 0.19 0.19 0.64 -0.25 0.11 -0.08
5 ts_lstm_5_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 1.35 1.37 2.45 -0.22 0.11 -0.07
6 ts_lstm_6_^DJI No Static ^DJI 2008-01-03 2008-12-31 0.94 0.67 0.67 1.64 -0.19 0.11 -0.07
7 ts_lstm_7_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 0.19 0.19 0.64 -0.25 0.11 -0.08
8 all_All_^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 1.35 1.37 2.45 -0.22 0.11 -0.07
9 ts_lstm_1_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.76 0.77 1.59 -0.21 0.12 -0.07
10 ts_lstm_2_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.76 0.77 1.59 -0.21 0.12 -0.07
11 ts_lstm_3_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.76 0.77 1.59 -0.21 0.12 -0.07
12 ts_lstm_4_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.32 0.32 0.87 -0.25 0.12 -0.08
13 ts_lstm_5_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.76 0.77 1.59 -0.21 0.12 -0.07
14 ts_lstm_6_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 0.95 0.56 0.57 1.36 -0.22 0.12 -0.07
15 ts_lstm_7_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.32 0.32 0.87 -0.25 0.12 -0.08
16 all_All_^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 0.76 0.77 1.59 -0.21 0.12 -0.07
17 ts_lstm_1_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 1.18 1.19 2.25 -0.14 0.12 -0.09
18 ts_lstm_2_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 1.18 1.19 2.25 -0.14 0.12 -0.09
19 ts_lstm_3_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 1.18 1.19 2.25 -0.14 0.12 -0.09
20 ts_lstm_4_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 0.84 0.84 1.78 -0.15 0.12 -0.09
21 ts_lstm_5_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 1.18 1.19 2.25 -0.14 0.12 -0.09
22 ts_lstm_6_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 0.97 0.97 0.98 2.05 -0.15 0.12 -0.09
23 ts_lstm_7_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 0.84 0.84 1.78 -0.15 0.12 -0.09
24 all_All_^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 1.18 1.19 2.25 -0.14 0.12 -0.09
25 Long-Only Trade Strategy for ^DJI No Static ^DJI 2008-01-03 2008-12-31 1.0 -0.33 -0.33 -0.86 -0.42 0.11 -0.08
26 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2008-01-03 2008-12-31 1.0 -0.4 -0.4 -1.02 -0.49 0.12 -0.09
27 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2008-01-03 2008-12-31 1.0 -0.38 -0.38 -0.94 -0.48 0.12 -0.09

Portfolio E

  1. Portfolio E: Long and Eleven Distinct Technical Analysis Based Trade Strategies for US Indixes

    Description:

     1. Portfolio with 39 trading strategies
     2. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Trade Strategies:

     1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold
    
     2. 33 trade strategies: Nasdaq, S&P 500, and DOW Jones using following TA Indicators & Configurations:
    
        See: https://technical-analysis-library-in-python.readthedocs.io/en/latest/index.html for 
        explanation on the technical indicator specific parameters
    
             TS-No    TA-Indicator                 Parameters
    
               1           sma           fast_mav                      10 
                                         slow_mav                      50 
                                         enter_if_last_nmatch           2 
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1
    
               2            bb           window                        20
                                         window_dev                     1
                                         enter_if_last_nmatch           2 
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1     
    
               3          macd           window_slow                   26
                                         window_fast                   12
                                         window_sign                    9
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
               4           rsi           enter_long if rsi  <=         30
                                         exit_long  if rsi  >          30
                                         enter_short if rsi >=         70
                                         exit_short if rsi  <=         60
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
               5          srsi           window                        14
                                         smooth1                        3
                                         smooth2                        3
                                         enter_long if stochrsi_d >=  0.5
                                         exit_long if stochrsi_d  <   0.5
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
               6           adx           window                        14
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
               7         mkama           kama_fast_window              10
                                         kama_fast_pow1                 2
                                         kama_fast_pow1                30
                                         kama_slow_window              10
                                         kama_slow_pow1                 5
                                         kama_slow_pow1                30
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
               8           tsi           window_slow                   25
                                         window_fast                    5
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
               9      forceidx           window                        13
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
              10           mfi           window                        14
                                         no mfi points for slope        5
                                         enter_if_last_nmatch           2
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1 
    
              11           sma           fast_mav                      15 
                                         slow_mav                      60 
                                         enter_if_last_nmatch           2 
                                         enter_if_cross_over_sig      Yes
                                         exit_if_last_nmatch            1
    
     3. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using the following configuration: 
    
         - A Composite Trade Strategy based on all the technical-analysis indicators configured 
           above
    
         - The Set Entry cofiguration rules are: 
           a. Majority Voting (default)
           b. Enter a trade if the last n voting decisions are the same, set to 1 (default )
           c. Enter a trade if there is cross-over signaled after applying rules a) and b), 
              set to False
    
         - The Set Exit configuration rules are: 
           a. Majority Voting (Default)
           b. Exit a trade if the last n exit decisions are the same, set to 1 (default )
    
    

    Backtest:

     1. Type: regular
     2. Test Period: 
         1. Begin Date = 2006-01-01 
         2. End Date   = 2010-12-31 
Portfolio Trade Assets
In [62]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [63]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [64]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [65]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )          
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #3

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_bb",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "bb",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 13, 'window_dev' : 1 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_macd",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 26, 'window_fast' : 12, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_rsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "rsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'rsi_enter_long'  : 30.0,  'rsi_exit_long'  : 30.0, 
                                                 'rsi_enter_short' : 70.0,  'rsi_exit_short' : 70.0 },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_srsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "srsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 14,  'smooth1' : 3, 'smooth2'  : 3,
                                                 'srsi_enter_long'  : 0.8,  'srsi_exit_long'  : 0.8,
                                                 'srsi_enter_short' : 0.2,  'srsi_exit_short' : 0.2 },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_adx",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "adx",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'adx_enter_long_ge' : 14, 'adx_exit_long_lt'  : 14,
                                             'adx_enter_short_ge' : 14, 'adx_exit_short_lt' : 14 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #8

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #9

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_forceindex",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "forceindex",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 39 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #11

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_mfi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "mfi",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'long_slope_win' : 15, 'short_slope_win' : 15 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [66]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio E",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [67]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  39
Execute Backtest
In [68]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio E",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2006-01-01", 
                                            strEndDate = "2010-12-31" ),
                    trade_asset_registered_item = portf_registered_obj )
In [69]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-12-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-02-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-04-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-05-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-06-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-07-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-08-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-09-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-11-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-12-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-02-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-03 00:00:00 
****************

Backtest Metrics
Save to Excel
In [70]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-E backtest-metrics.xlsx")
Execution & Investment Metrics
In [71]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']]
Out[71]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
0 Portfolio E Yes 3085 78000000.0 9.121777e+07 0.169459 Completed
1 ts_sma_1_^DJI No 27 2000000.0 3.735230e+06 0.867615 Completed
2 ts_sma_2_^DJI No 21 2000000.0 2.955567e+06 0.477783 Completed
3 ts_bb_^DJI No 159 2000000.0 3.070057e+06 0.535028 Completed
4 ts_macd_^DJI No 101 2000000.0 2.411088e+06 0.205544 Completed
5 ts_rsi_^DJI No 33 2000000.0 2.413782e+06 0.206891 Completed
6 ts_srsi_^DJI No 105 2000000.0 1.432085e+06 -0.283958 Completed
7 ts_adx_^DJI No 101 2000000.0 1.679677e+06 -0.160161 Completed
8 ts_kama_^DJI No 13 2000000.0 2.476559e+06 0.238279 Completed
9 ts_tsi_^DJI No 61 2000000.0 2.005830e+06 0.002915 Completed
10 ts_forceindex_^DJI No 111 2000000.0 1.276673e+06 -0.361663 Completed
11 ts_mfi_^DJI No 108 2000000.0 2.246942e+06 0.123471 Completed
12 all_All_^DJI No 186 2000000.0 1.873794e+06 -0.063103 Completed
13 ts_sma_1_^IXIC No 29 2000000.0 3.126297e+06 0.563149 Completed
14 ts_sma_2_^IXIC No 23 2000000.0 2.690137e+06 0.345069 Completed
15 ts_bb_^IXIC No 156 2000000.0 2.260866e+06 0.130433 Completed
16 ts_macd_^IXIC No 103 2000000.0 1.783791e+06 -0.108104 Completed
17 ts_rsi_^IXIC No 32 2000000.0 2.206864e+06 0.103432 Completed
18 ts_srsi_^IXIC No 113 2000000.0 1.278512e+06 -0.360744 Completed
19 ts_adx_^IXIC No 94 2000000.0 3.318816e+06 0.659408 Completed
20 ts_kama_^IXIC No 15 2000000.0 2.420422e+06 0.210211 Completed
21 ts_tsi_^IXIC No 60 2000000.0 2.792722e+06 0.396361 Completed
22 ts_forceindex_^IXIC No 107 2000000.0 3.107906e+06 0.553953 Completed
23 ts_mfi_^IXIC No 116 2000000.0 1.752477e+06 -0.123762 Completed
24 all_All_^IXIC No 179 2000000.0 3.275147e+06 0.637573 Completed
25 ts_sma_1_^GSPC No 29 2000000.0 2.535135e+06 0.267568 Completed
26 ts_sma_2_^GSPC No 23 2000000.0 2.799919e+06 0.399960 Completed
27 ts_bb_^GSPC No 150 2000000.0 2.808892e+06 0.404446 Completed
28 ts_macd_^GSPC No 107 2000000.0 1.946169e+06 -0.026915 Completed
29 ts_rsi_^GSPC No 40 2000000.0 2.497663e+06 0.248831 Completed
30 ts_srsi_^GSPC No 116 2000000.0 1.295493e+06 -0.352254 Completed
31 ts_adx_^GSPC No 96 2000000.0 2.242212e+06 0.121106 Completed
32 ts_kama_^GSPC No 11 2000000.0 2.974697e+06 0.487349 Completed
33 ts_tsi_^GSPC No 77 2000000.0 1.563528e+06 -0.218236 Completed
34 ts_forceindex_^GSPC No 107 2000000.0 1.708216e+06 -0.145892 Completed
35 ts_mfi_^GSPC No 98 2000000.0 2.160516e+06 0.080258 Completed
36 all_All_^GSPC No 175 2000000.0 2.612804e+06 0.306402 Completed
37 Long-Only Trade Strategy for ^DJI No 1 2000000.0 2.134338e+06 0.067169 Completed
38 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.364535e+06 0.182267 Completed
39 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 1.982412e+06 -0.008794 Completed
Performance Metrics
In [72]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[72]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio E Yes 2006-01-04 2010-12-31 1.0 0.17 0.03 0.4 -0.09 0.04 -0.03
1 ts_sma_1_^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 0.87 0.13 0.75 -0.21 0.07 -0.07
2 ts_sma_2_^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 0.48 0.08 0.54 -0.17 0.06 -0.06
3 ts_bb_^DJI No Static ^DJI 2006-01-04 2010-12-31 0.84 0.54 0.09 0.53 -0.22 0.11 -0.08
4 ts_macd_^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 0.21 0.04 0.28 -0.22 0.07 -0.08
5 ts_rsi_^DJI No Static ^DJI 2006-01-04 2010-12-31 0.13 0.21 0.04 0.53 -0.09 0.11 -0.07
6 ts_srsi_^DJI No Static ^DJI 2006-01-04 2010-12-31 0.58 -0.28 -0.06 -0.38 -0.36 0.07 -0.09
7 ts_adx_^DJI No Static ^DJI 2006-01-04 2010-12-31 0.96 -0.16 -0.03 -0.09 -0.33 0.08 -0.07
8 ts_kama_^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 0.24 0.04 0.34 -0.27 0.05 -0.05
9 ts_tsi_^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 0.0 0.0 0.1 -0.31 0.07 -0.07
10 ts_forceindex_^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 -0.36 -0.09 -0.34 -0.46 0.06 -0.08
11 ts_mfi_^DJI No Static ^DJI 2006-01-04 2010-12-31 0.68 0.12 0.02 0.22 -0.27 0.07 -0.09
12 all_All_^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 -0.06 -0.01 0.03 -0.3 0.08 -0.07
13 ts_sma_1_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 1.0 0.57 0.09 0.51 -0.3 0.09 -0.07
14 ts_sma_2_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 1.0 0.35 0.06 0.38 -0.3 0.09 -0.07
15 ts_bb_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 0.85 0.13 0.02 0.22 -0.25 0.12 -0.07
16 ts_macd_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 0.99 -0.11 -0.02 0.02 -0.32 0.08 -0.09
17 ts_rsi_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 0.12 0.1 0.02 0.25 -0.12 0.12 -0.06
18 ts_srsi_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 0.6 -0.36 -0.09 -0.4 -0.43 0.07 -0.11
19 ts_adx_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 0.92 0.66 0.11 0.58 -0.31 0.09 -0.07
20 ts_kama_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 1.0 0.21 0.04 0.29 -0.34 0.08 -0.07
21 ts_tsi_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 1.0 0.39 0.07 0.41 -0.3 0.08 -0.06
22 ts_forceindex_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 1.0 0.56 0.09 0.51 -0.24 0.09 -0.07
23 ts_mfi_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 0.68 -0.13 -0.03 -0.03 -0.46 0.09 -0.07
24 all_All_^IXIC No Static ^IXIC 2006-01-04 2010-12-31 1.0 0.64 0.1 0.56 -0.31 0.08 -0.06
25 ts_sma_1_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 1.0 0.27 0.05 0.33 -0.29 0.09 -0.07
26 ts_sma_2_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 1.0 0.4 0.07 0.44 -0.24 0.07 -0.06
27 ts_bb_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 0.83 0.4 0.07 0.42 -0.23 0.12 -0.09
28 ts_macd_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 0.94 -0.03 -0.01 0.09 -0.22 0.09 -0.09
29 ts_rsi_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 0.12 0.25 0.05 0.6 -0.1 0.12 -0.08
30 ts_srsi_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 0.56 -0.35 -0.08 -0.45 -0.41 0.08 -0.1
31 ts_adx_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 0.94 0.12 0.02 0.21 -0.35 0.09 -0.07
32 ts_kama_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 1.0 0.49 0.08 0.53 -0.23 0.06 -0.05
33 ts_tsi_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 1.0 -0.22 -0.05 -0.13 -0.35 0.08 -0.06
34 ts_forceindex_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 1.0 -0.15 -0.03 -0.05 -0.39 0.09 -0.07
35 ts_mfi_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 0.67 0.08 0.02 0.18 -0.42 0.09 -0.09
36 all_All_^GSPC No Static ^GSPC 2006-01-04 2010-12-31 0.99 0.31 0.06 0.37 -0.19 0.08 -0.06
37 Long-Only Trade Strategy for ^DJI No Static ^DJI 2006-01-04 2010-12-31 1.0 0.07 0.01 0.17 -0.54 0.11 -0.08
38 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2006-01-04 2010-12-31 1.0 0.18 0.03 0.26 -0.56 0.12 -0.09
39 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2006-01-04 2010-12-31 1.0 -0.01 -0.0 0.12 -0.57 0.12 -0.09

Portfolio F

  1. Portfolio F: Long and Multiple Configured AI-Modeled Trade Strategies for US Indixes

    Description:

     1. Portfolio with 30 trading strategies
     2. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Trade Strategies:

     1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold
     2. 24 trade strategies: Nasdaq, S&P 500, and DOW Jones using the following AI-Models
        and corresponding configurations:
    
                                                        Trading AI-Models
    
           Parameter                 #1      #2      #3        #4          #5        #6        #7
    
        ai-model                    GRU    LSTM Conv1d-GRU Conv1d-LSTM  Wavenet  Wavenet-GRU  GRU
        epochs                       20      20      20        20          20        20        20
        no neurons layer 1           20      20      20        20           -        20        20
        no neurons layer 2           20      20      20        20           -        20        20
        time series length           50      50      50        50          50        50        40         
        no predictions ahead          5       5       5         5           5         5         3
        extend trade dyn            Yes     Yes     Yes       Yes         Yes       Yes       Yes
        re_evalaute_exit_dyn        Yes     Yes     Yes       Yes         Yes       Yes       Yes
        enter_if_last_nmatch          1       1       1         1           1         1         1
        enter_if_cross_over_sig      No      No      No        No          No        No        No
        exit_if_last_nmatch           1       1       1         1           1         1         1
    
           Parameter                 #8              
    
        ai-model                 Wavenet-LSTM 
        epochs                        20           
        no neurons layer 1            20           
        no neurons layer 2            20           
        time series length            50                    
        no predictions ahead           5            
        extend trade dyn             Yes          
        re_evalaute_exit_dyn         Yes          
        enter_if_last_nmatch           1            
        enter_if_cross_over_sig       No           
        exit_if_last_nmatch            1            
    
        Note: 
          - the parameters "no neurons layer 1" and "no neurons layer 2" are only applicable to 
            AI Models that have GRU or LSTM layers. 
          - Conv1d is a convulation layer in one dimension (configured with 40 filters )
          - Wavenet is an AI Architectured based on a set of Convolutional Layers
    
     3. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using the following Composite 
        model configuration: 
    
         - A Composite Trade Strategy based on all the AI Trading Models configured above
    
         - The Set Entry cofiguration rules are: 
           a. Majority Voting (default)
           b. Enter a trade if the last n voting decisions are the same, set to 1 (default )
           c. Enter a trade if there is cross-over signaled after applying rules a) and b), 
              set to False (default)
    
         - The Set Exit configuration rules are: 
           a. Majority Voting (Default)
               - Exit a long trade if the percent of Trading AI Models signaled an exit for a long position
                  is greater that the percent signaling no-exit 
               - Exit a short trade if the percent of Trading AI Models signaled an exit for a short position
                  is greater that the percent signaling no-exit 
           b. Exit a trade if the last n exit decisions are the same, set to 1 (default )
    
    

    Backtest:

     1. Type: regular
    
     2. AI Models Fit Date Ranges
         1. Training Period: 
             1. Begin Date = 2002-01-01 
             2. End Date   = 2006-12-31  
         2. Validation Period: 
             1. Begin Date = 2007-01-01 
             2. End Date   = 2008-12-31 
    
     3. Test Period: 
         1. Begin Date = 2009-01-01 
         2. End Date   = 2009-12-31         
Portfolio Trade Assets
In [73]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [74]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        forceCreateMarketData = False,
        interval               = "1d"  ) 
Simulation Broker
In [75]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [76]:
# Define Metadata for several Trading AI-Models for several Trade Strategies in the portfolio and one
# Trade Strategy based on a composite set of all Trading AI-Models. The composite trade strategy
# uses Majority Voting for entering and exiting a trade (default setting)

# The configuraiton data for each Trade Strategy is defined via a JSON/dict, and 
# they are added to the TradeStrategyConfigData() object
# 
# This configuration method is a short-cut when creating many trade strategies in a portfolio, or 
# a composite of many trade strategies. The JSON format follows the general format:
#
# *** Trade Strategy Config:
#
# 1. ts_unique_tag : unique tag to identify a trade strategy in a set
# 2. actions_conf : dict, 
#       Description: contains the configuration data for each action in a trade strategy, only
#                    the "entry_exit", sub-tag is required
#       Child tags:
#             "entry_exit" : required
#             "stop_lost"  : optional
#             "pos_sizing" : optional
#             "pyramiding" : optional
# 3. The format of each child-tag/action follows the same parameters as when defined via the class,
# 4. obj_args : custom set of parameters passed to the defined model defined via the model tag, this
#               is a dynamic set of parameters and specific to each model, some share common inputs.
#
#    Supported built-in models, for the entry_exit action:
#        [ "sma", "bb", "macd", "rsi", "srsi", "adx", "kama", "tsi",
#          "forceindex", "mfi", 'conv1d_gru', 'conv1d_lstm', 'wavenet', 
#          'wavenet_gru', 'wavenet_lstm', 'lstm', 'gru' ]
#
#    Custom models can be added via a custom function. The second strategy in the configuration
#    below ('ts_unique_tag' : "ts_gru_1") , defines the "custom_create_func" tag and sets equal to
#    "create_actions_ai_ts_model", this function should be already defined or imported. Thus for
#    trade strategy #2, the user custom function is used. Note, that for trade strategy: ts_gru_2
#    the model is also set to "gru", but in this case it is using the built-in gru model.
#    The actual implementantions for all supported models are included in this Jupyter Notebook, at
#    the beg. of this portfolio example, and a user can copy and altered as they see fit, it would
#    affect the built-in functions, which are scope in a pythong package.
#
#
# *** Trade Strategy Set Config:
#
# There is only one set configuration, and it is defined to apply policies on how to treat the 
# set actions, this configuration is optional, and defaults for each action are defined below
#
# "entry" : optional
#     Defines the policy to drive the trade decision to follow from the set. As explained in earlier 
#     examples. 
#     Default policy parameters are:
#           Majority Voting, 
#           incNoInvestInVotingDec = False, 
#           lastn_match = 1
#           cross_over_signal_for_trading
#
# "exit" : optional
#     Defines the policy to drive the exit decision to follow from the set. As explained in earlier 
#     examples. 
#     Default policy parameters are:
#           Majority Voting, 
#           lastn_match = 1
#

tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [77]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio F",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [78]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  30
Training, Validation and Test Periods for Backtest
In [79]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2001-07-01",
                             strBegDate         = "2002-01-01",
                             strEndDate         = "2006-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2006-07-01",
                               strBegDate         = "2007-01-01",
                               strEndDate         = "2008-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2008-07-01",
                               strBegDate         = "2009-01-01",
                               strEndDate         = "2009-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
Execute Backtest
In [80]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio F",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [81]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************

Backtest Metrics
Save to Excel
In [82]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-F backtest-metrics.xlsx")
Execution & Investment Metrics
In [83]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']]
Out[83]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
0 Portfolio F Yes 1066 60000000.0 6.468605e+07 0.078101 Completed
1 ts_gru_1_^DJI No 56 2000000.0 2.768343e+06 0.384172 Completed
2 ts_lstm_^DJI No 52 2000000.0 2.336025e+06 0.168013 Completed
3 ts_conv1d_gru_^DJI No 60 2000000.0 2.061737e+06 0.030868 Completed
4 ts_conv1d_lstm_^DJI No 52 2000000.0 2.826407e+06 0.413204 Completed
5 ts_wavenet_^DJI No 46 2000000.0 2.185845e+06 0.092923 Completed
6 ts_wavenet_gru_^DJI No 52 2000000.0 2.293320e+06 0.146660 Completed
7 ts_wavenet_lstm_^DJI No 70 2000000.0 2.215337e+06 0.107668 Completed
8 ts_gru_2_^DJI No 56 2000000.0 2.768343e+06 0.384172 Completed
9 all_All_^DJI No 60 2000000.0 2.733866e+06 0.366933 Completed
10 ts_gru_1_^IXIC No 48 2000000.0 1.374006e+06 -0.312997 Completed
11 ts_lstm_^IXIC No 33 2000000.0 1.412792e+06 -0.293604 Completed
12 ts_conv1d_gru_^IXIC No 40 2000000.0 1.374142e+06 -0.312929 Completed
13 ts_conv1d_lstm_^IXIC No 56 2000000.0 2.215471e+06 0.107735 Completed
14 ts_wavenet_^IXIC No 41 2000000.0 1.793882e+06 -0.103059 Completed
15 ts_wavenet_gru_^IXIC No 38 2000000.0 2.215847e+06 0.107923 Completed
16 ts_wavenet_lstm_^IXIC No 72 2000000.0 2.389811e+06 0.194906 Completed
17 ts_gru_2_^IXIC No 48 2000000.0 1.374006e+06 -0.312997 Completed
18 all_All_^IXIC No 51 2000000.0 1.446419e+06 -0.276791 Completed
19 ts_gru_1_^GSPC No 16 2000000.0 2.001147e+06 0.000574 Completed
20 ts_lstm_^GSPC No 21 2000000.0 1.689975e+06 -0.155012 Completed
21 ts_conv1d_gru_^GSPC No 30 2000000.0 2.595040e+06 0.297520 Completed
22 ts_conv1d_lstm_^GSPC No 3 2000000.0 2.498398e+06 0.249199 Completed
23 ts_wavenet_^GSPC No 6 2000000.0 2.068429e+06 0.034215 Completed
24 ts_wavenet_gru_^GSPC No 12 2000000.0 2.207892e+06 0.103946 Completed
25 ts_wavenet_lstm_^GSPC No 13 2000000.0 2.363158e+06 0.181579 Completed
26 ts_gru_2_^GSPC No 16 2000000.0 2.001147e+06 0.000574 Completed
27 all_All_^GSPC No 15 2000000.0 1.993714e+06 -0.003143 Completed
28 Long-Only Trade Strategy for ^DJI No 1 2000000.0 2.307932e+06 0.153966 Completed
29 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.780251e+06 0.390126 Completed
30 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 2.393362e+06 0.196681 Completed
Performance Metrics
In [84]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[84]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio F Yes 2009-01-05 2009-12-31 1.0 0.08 0.08 0.61 -0.14 0.06 -0.04
1 ts_gru_1_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.39 0.39 1.47 -0.17 0.07 -0.04
2 ts_lstm_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.17 0.17 0.76 -0.18 0.07 -0.04
3 ts_conv1d_gru_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.03 0.03 0.25 -0.25 0.06 -0.08
4 ts_conv1d_lstm_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.41 0.42 1.56 -0.18 0.07 -0.04
5 ts_wavenet_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.09 0.1 0.49 -0.21 0.07 -0.05
6 ts_wavenet_gru_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.15 0.15 0.69 -0.21 0.07 -0.05
7 ts_wavenet_lstm_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.11 0.11 0.55 -0.24 0.07 -0.05
8 ts_gru_2_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.39 0.39 1.47 -0.17 0.07 -0.04
9 all_All_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.37 0.37 1.45 -0.18 0.07 -0.04
10 ts_gru_1_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.31 -0.31 -1.1 -0.36 0.08 -0.08
11 ts_lstm_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.29 -0.29 -0.92 -0.33 0.08 -0.08
12 ts_conv1d_gru_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.31 -0.31 -1.09 -0.39 0.05 -0.08
13 ts_conv1d_lstm_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.12 0.12 0.52 -0.27 0.08 -0.08
14 ts_wavenet_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.1 -0.1 -0.18 -0.26 0.08 -0.08
15 ts_wavenet_gru_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.12 0.12 0.51 -0.23 0.08 -0.08
16 ts_wavenet_lstm_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.2 0.21 0.79 -0.15 0.08 -0.04
17 ts_gru_2_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.31 -0.31 -1.1 -0.36 0.08 -0.08
18 all_All_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.27 -0.28 -0.94 -0.34 0.08 -0.08
19 ts_gru_1_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.0 0.0 0.15 -0.21 0.07 -0.05
20 ts_lstm_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 -0.15 -0.15 -0.43 -0.25 0.07 -0.05
21 ts_conv1d_gru_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.3 0.31 1.11 -0.22 0.07 -0.05
22 ts_conv1d_lstm_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.25 0.26 0.97 -0.26 0.07 -0.05
23 ts_wavenet_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.03 0.03 0.25 -0.28 0.07 -0.05
24 ts_wavenet_gru_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.11 0.11 0.51 -0.26 0.07 -0.05
25 ts_wavenet_lstm_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.18 0.18 0.74 -0.28 0.07 -0.05
26 ts_gru_2_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.0 0.0 0.15 -0.21 0.07 -0.05
27 all_All_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 -0.0 -0.0 0.13 -0.22 0.07 -0.05
28 Long-Only Trade Strategy for ^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.15 0.16 0.72 -0.27 0.07 -0.05
29 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.39 0.4 1.32 -0.23 0.07 -0.06
30 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.2 0.2 0.8 -0.28 0.07 -0.05

Portfolio G

  1. Portfolio G: Combines all Trade Strategies in Portfolio E and F

    Description:

     1. Portfolio with 63 trading strategies
     2. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Trade Strategies:

     1. Three trade strategies: Nasdaq, S&P 500, and DOW Jones with buy-and-hold
    
     2. Fifty-Seven trade strategies, 19 trade strategies per US Index, as defined in
        Portfolio E and F
    
     3. Three trade strategies: Nasdaq, S&P 500, and DOW Jones using the following Composite 
        model configuration: 
    
         - A Composite Trade Strategy based on all the Trading Models configured above per US Index
    
         - The Set Entry cofiguration rules are: 
           a. Majority Voting (default)
           b. Enter a trade if the last n voting decisions are the same, set to 1 (default )
           c. Enter a trade if there is cross-over signaled after applying rules a) and b), 
              set to False (default)
    
         - The Set Exit configuration rules are: 
           a. Majority Voting (Default)
               - Exit a long trade if the percent of Trading Models signaled an exit for a long position
                  is greater that the percent signaling no-exit 
               - Exit a short trade if the percent of Trading Models signaled an exit for a short position
                  is greater that the percent signaling no-exit 
           b. Exit a trade if the last n exit decisions are the same, set to 1 (default )

Backtest:

1. Type: regular

2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2001-01-01 
        2. End Date   = 2006-12-31  
    2. Validation Period: 
        1. Begin Date = 2007-01-01 
        2. End Date   = 2008-12-31 

3. Test Period: 
    1. Begin Date = 2009-01-01 
    2. End Date   = 2009-12-31         
Portfolio Trade Assets
In [85]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [86]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [87]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [88]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

# TS #9

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #11

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_bb",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "bb",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 13, 'window_dev' : 1 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #12

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_macd",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 26, 'window_fast' : 12, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #13

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_rsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "rsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'rsi_enter_long'  : 30.0,  'rsi_exit_long'  : 30.0, 
                                                 'rsi_enter_short' : 70.0,  'rsi_exit_short' : 70.0 },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #14

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_srsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "srsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 14,  'smooth1' : 3, 'smooth2'  : 3,
                                                 'srsi_enter_long'  : 0.8,  'srsi_exit_long'  : 0.8,
                                                 'srsi_enter_short' : 0.2,  'srsi_exit_short' : 0.2 },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #15

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_adx",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "adx",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'adx_enter_long_ge' : 14, 'adx_exit_long_lt'  : 14,
                                             'adx_enter_short_ge' : 14, 'adx_exit_short_lt' : 14 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #16

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #17

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #118

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_forceindex",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "forceindex",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 39 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #19

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_mfi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "mfi",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'long_slope_win' : 15, 'short_slope_win' : 15 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [89]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio G",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [90]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  63
Training, Validation and Test Periods for Backtest
In [91]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2000-07-01",
                             strBegDate         = "2001-01-01",
                             strEndDate         = "2006-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2006-07-01",
                               strBegDate         = "2007-01-01",
                               strEndDate         = "2008-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2008-07-01",
                               strBegDate         = "2009-01-01",
                               strEndDate         = "2009-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
Execute Backtest
In [92]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio G",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [93]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************

Backtest Metrics
Save to Excel
In [94]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-G backtest-metrics.xlsx")
Trade Strategies Execution & Investment Metrics

DOW Jones

In [95]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[95]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_gru_1_^DJI No 58 2000000.0 2.057182e+06 0.028591 Completed
2 ts_lstm_^DJI No 58 2000000.0 2.818011e+06 0.409006 Completed
3 ts_conv1d_gru_^DJI No 64 2000000.0 2.094009e+06 0.047005 Completed
4 ts_conv1d_lstm_^DJI No 60 2000000.0 3.114479e+06 0.557239 Completed
5 ts_wavenet_^DJI No 46 2000000.0 2.214619e+06 0.107309 Completed
6 ts_wavenet_gru_^DJI No 38 2000000.0 2.100789e+06 0.050394 Completed
7 ts_wavenet_lstm_^DJI No 64 2000000.0 1.991320e+06 -0.004340 Completed
8 ts_gru_2_^DJI No 58 2000000.0 2.057182e+06 0.028591 Completed
9 ts_sma_1_^DJI No 6 2000000.0 2.364218e+06 0.182109 Completed
10 ts_sma_2_^DJI No 4 2000000.0 2.454342e+06 0.227171 Completed
11 ts_bb_^DJI No 46 2000000.0 1.871576e+06 -0.064212 Completed
12 ts_macd_^DJI No 21 2000000.0 1.806770e+06 -0.096615 Completed
13 ts_rsi_^DJI No 11 2000000.0 2.163535e+06 0.081767 Completed
14 ts_srsi_^DJI No 39 2000000.0 2.055189e+06 0.027594 Completed
15 ts_adx_^DJI No 22 2000000.0 2.145323e+06 0.072661 Completed
16 ts_kama_^DJI No 3 2000000.0 2.651584e+06 0.325792 Completed
17 ts_tsi_^DJI No 7 2000000.0 2.550576e+06 0.275288 Completed
18 ts_forceindex_^DJI No 14 2000000.0 2.318934e+06 0.159467 Completed
19 ts_mfi_^DJI No 32 2000000.0 1.724653e+06 -0.137674 Completed
20 all_All_^DJI No 88 2000000.0 2.006314e+06 0.003157 Completed
61 Long-Only Trade Strategy for ^DJI No 1 2000000.0 2.307932e+06 0.153966 Completed

Nasdaq

In [96]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[96]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
21 ts_gru_1_^IXIC No 35 2000000.0 1.741611e+06 -0.129194 Completed
22 ts_lstm_^IXIC No 64 2000000.0 1.810093e+06 -0.094953 Completed
23 ts_conv1d_gru_^IXIC No 29 2000000.0 1.311181e+06 -0.344410 Completed
24 ts_conv1d_lstm_^IXIC No 27 2000000.0 1.592466e+06 -0.203767 Completed
25 ts_wavenet_^IXIC No 35 2000000.0 2.095864e+06 0.047932 Completed
26 ts_wavenet_gru_^IXIC No 34 2000000.0 1.591491e+06 -0.204255 Completed
27 ts_wavenet_lstm_^IXIC No 27 2000000.0 1.912207e+06 -0.043897 Completed
28 ts_gru_2_^IXIC No 35 2000000.0 1.741611e+06 -0.129194 Completed
29 ts_sma_1_^IXIC No 7 2000000.0 2.194664e+06 0.097332 Completed
30 ts_sma_2_^IXIC No 6 2000000.0 2.614429e+06 0.307214 Completed
31 ts_bb_^IXIC No 40 2000000.0 2.008552e+06 0.004276 Completed
32 ts_macd_^IXIC No 30 2000000.0 1.793276e+06 -0.103362 Completed
33 ts_rsi_^IXIC No 4 2000000.0 1.833041e+06 -0.083479 Completed
34 ts_srsi_^IXIC No 46 2000000.0 1.971988e+06 -0.014006 Completed
35 ts_adx_^IXIC No 18 2000000.0 2.060949e+06 0.030474 Completed
36 ts_kama_^IXIC No 3 2000000.0 2.587777e+06 0.293889 Completed
37 ts_tsi_^IXIC No 10 2000000.0 1.954290e+06 -0.022855 Completed
38 ts_forceindex_^IXIC No 15 2000000.0 2.101716e+06 0.050858 Completed
39 ts_mfi_^IXIC No 36 2000000.0 1.840780e+06 -0.079610 Completed
40 all_All_^IXIC No 70 2000000.0 1.308570e+06 -0.345715 Completed
62 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.780251e+06 0.390126 Completed

S&P 500

In [97]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[97]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
41 ts_gru_1_^GSPC No 28 2000000.0 1.839754e+06 -0.080123 Completed
42 ts_lstm_^GSPC No 23 2000000.0 2.038848e+06 0.019424 Completed
43 ts_conv1d_gru_^GSPC No 26 2000000.0 1.729171e+06 -0.135414 Completed
44 ts_conv1d_lstm_^GSPC No 10 2000000.0 1.407817e+06 -0.296092 Completed
45 ts_wavenet_^GSPC No 20 2000000.0 2.340107e+06 0.170054 Completed
46 ts_wavenet_gru_^GSPC No 19 2000000.0 2.037022e+06 0.018511 Completed
47 ts_wavenet_lstm_^GSPC No 7 2000000.0 2.359970e+06 0.179985 Completed
48 ts_gru_2_^GSPC No 28 2000000.0 1.839754e+06 -0.080123 Completed
49 ts_sma_1_^GSPC No 7 2000000.0 2.127003e+06 0.063501 Completed
50 ts_sma_2_^GSPC No 7 2000000.0 2.497942e+06 0.248971 Completed
51 ts_bb_^GSPC No 36 2000000.0 2.103086e+06 0.051543 Completed
52 ts_macd_^GSPC No 34 2000000.0 1.563905e+06 -0.218047 Completed
53 ts_rsi_^GSPC No 12 2000000.0 2.209188e+06 0.104594 Completed
54 ts_srsi_^GSPC No 41 2000000.0 1.748147e+06 -0.125927 Completed
55 ts_adx_^GSPC No 23 2000000.0 2.151969e+06 0.075985 Completed
56 ts_kama_^GSPC No 2 2000000.0 2.525237e+06 0.262618 Completed
57 ts_tsi_^GSPC No 10 2000000.0 2.139257e+06 0.069629 Completed
58 ts_forceindex_^GSPC No 15 2000000.0 2.037685e+06 0.018842 Completed
59 ts_mfi_^GSPC No 35 2000000.0 1.777566e+06 -0.111217 Completed
60 all_All_^GSPC No 50 2000000.0 1.921266e+06 -0.039367 Completed
63 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 2.393362e+06 0.196681 Completed
Performance Metrics

Dow Jones

In [98]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')
Out[98]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 ts_gru_1_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.03 0.03 0.24 -0.2 0.07 -0.04
2 ts_lstm_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.41 0.42 1.55 -0.18 0.07 -0.04
3 ts_conv1d_gru_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.05 0.05 0.31 -0.24 0.06 -0.08
4 ts_conv1d_lstm_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.56 0.57 1.97 -0.18 0.07 -0.04
5 ts_wavenet_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.11 0.11 0.55 -0.19 0.07 -0.04
6 ts_wavenet_gru_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.05 0.05 0.33 -0.24 0.07 -0.04
7 ts_wavenet_lstm_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 -0.0 -0.0 0.11 -0.25 0.07 -0.05
8 ts_gru_2_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.03 0.03 0.24 -0.2 0.07 -0.04
9 ts_sma_1_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.18 0.19 0.87 -0.15 0.05 -0.06
10 ts_sma_2_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.23 0.23 1.12 -0.17 0.04 -0.05
11 ts_bb_^DJI No Static ^DJI 2009-01-05 2009-12-31 0.81 -0.06 -0.06 -0.2 -0.22 0.06 -0.07
12 ts_macd_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 -0.1 -0.1 -0.35 -0.23 0.07 -0.05
13 ts_rsi_^DJI No Static ^DJI 2009-01-05 2009-12-31 0.11 0.08 0.08 0.96 -0.03 0.06 -0.03
14 ts_srsi_^DJI No Static ^DJI 2009-01-05 2009-12-31 0.55 0.03 0.03 0.24 -0.15 0.07 -0.05
15 ts_adx_^DJI No Static ^DJI 2009-01-05 2009-12-31 0.97 0.07 0.07 0.46 -0.21 0.04 -0.04
16 ts_kama_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.33 0.33 1.52 -0.19 0.04 -0.05
17 ts_tsi_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.27 0.28 1.2 -0.11 0.07 -0.04
18 ts_forceindex_^DJI No Static ^DJI 2009-01-05 2009-12-31 0.99 0.16 0.16 0.8 -0.13 0.04 -0.05
19 ts_mfi_^DJI No Static ^DJI 2009-01-05 2009-12-31 0.61 -0.14 -0.14 -0.8 -0.27 0.04 -0.04
20 all_All_^DJI No Static ^DJI 2009-01-05 2009-12-31 0.99 0.0 0.0 0.13 -0.17 0.07 -0.04
61 Long-Only Trade Strategy for ^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.15 0.16 0.72 -0.27 0.07 -0.05

Nasdaq

In [99]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')
Out[99]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
21 ts_gru_1_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.12 -0.12 -0.29 -0.26 0.08 -0.08
22 ts_lstm_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.09 -0.09 -0.17 -0.2 0.08 -0.06
23 ts_conv1d_gru_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.35 -0.35 -1.27 -0.4 0.08 -0.08
24 ts_conv1d_lstm_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.2 -0.2 -0.6 -0.32 0.08 -0.08
25 ts_wavenet_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.05 0.06 0.33 -0.18 0.07 -0.07
26 ts_wavenet_gru_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.2 -0.2 -0.58 -0.28 0.08 -0.08
27 ts_wavenet_lstm_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.05 -0.05 -0.03 -0.23 0.07 -0.07
28 ts_gru_2_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.12 -0.12 -0.29 -0.26 0.08 -0.08
29 ts_sma_1_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.1 0.11 0.51 -0.21 0.05 -0.07
30 ts_sma_2_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.32 0.32 1.13 -0.19 0.05 -0.07
31 ts_bb_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 0.75 0.01 0.01 0.17 -0.17 0.07 -0.07
32 ts_macd_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 0.97 -0.11 -0.11 -0.31 -0.16 0.07 -0.05
33 ts_rsi_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 0.08 -0.08 -0.08 -1.17 -0.11 0.02 -0.06
34 ts_srsi_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 0.63 -0.01 -0.01 0.05 -0.21 0.07 -0.06
35 ts_adx_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 0.96 0.03 0.03 0.25 -0.14 0.07 -0.05
36 ts_kama_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.3 0.31 1.16 -0.23 0.05 -0.06
37 ts_tsi_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.03 -0.03 0.02 -0.21 0.07 -0.05
38 ts_forceindex_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.04 0.04 0.29 -0.21 0.07 -0.05
39 ts_mfi_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 0.58 -0.07 -0.07 -0.27 -0.15 0.06 -0.06
40 all_All_^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 -0.34 -0.35 -1.23 -0.38 0.05 -0.09
62 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.39 0.4 1.32 -0.23 0.07 -0.06

S&P 500

In [100]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')
Out[100]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
41 ts_gru_1_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 -0.08 -0.08 -0.14 -0.26 0.07 -0.05
42 ts_lstm_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.02 0.02 0.22 -0.24 0.07 -0.05
43 ts_conv1d_gru_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 -0.13 -0.13 -0.37 -0.28 0.06 -0.07
44 ts_conv1d_lstm_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 -0.29 -0.3 -0.97 -0.38 0.06 -0.07
45 ts_wavenet_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.17 0.17 0.7 -0.28 0.07 -0.05
46 ts_wavenet_gru_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.02 0.02 0.19 -0.28 0.07 -0.05
47 ts_wavenet_lstm_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.18 0.18 0.74 -0.28 0.07 -0.05
48 ts_gru_2_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 -0.08 -0.08 -0.14 -0.26 0.07 -0.05
49 ts_sma_1_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.07 0.07 0.38 -0.17 0.05 -0.06
50 ts_sma_2_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.25 0.26 1.03 -0.18 0.05 -0.06
51 ts_bb_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 0.75 0.05 0.06 0.34 -0.18 0.06 -0.07
52 ts_macd_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 0.94 -0.22 -0.22 -0.88 -0.26 0.07 -0.05
53 ts_rsi_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 0.1 0.1 0.11 1.1 -0.04 0.06 -0.04
54 ts_srsi_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 0.55 -0.13 -0.13 -0.58 -0.21 0.07 -0.06
55 ts_adx_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 0.98 0.08 0.08 0.42 -0.17 0.07 -0.04
56 ts_kama_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.27 0.27 1.14 -0.22 0.04 -0.05
57 ts_tsi_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.07 0.07 0.38 -0.15 0.07 -0.04
58 ts_forceindex_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 0.98 0.02 0.02 0.19 -0.17 0.05 -0.05
59 ts_mfi_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 0.5 -0.11 -0.11 -0.53 -0.17 0.05 -0.06
60 all_All_^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 -0.04 -0.04 -0.01 -0.18 0.07 -0.05
63 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.2 0.2 0.8 -0.28 0.07 -0.05

Portfolio H

Portfolio H: Utilized Leveraged ETFs for Trading on The Model Security

- All models are trained on their corresponding US Index/model, but the trade enter via a broker is with
  the underlying leveraged ETF.

- $2,000,000/strategy

- ETF data for US Indixes not available until 2011 in yahoo finance

- Seven Trade Strategies are executed with ETF trading enable

- Additionally, there is a composite trade strategy for all ETF strategies a

Backtest:

1. Type: regular

2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2007-01-01 
        2. End Date   = 2012-12-31  
    2. Validation Period: 
        1. Begin Date = 2013-01-01 
        2. End Date   = 2014-12-31 

3. Test Period: 
    1. Begin Date = 2015-01-01 
    2. End Date   = 2015-12-31         
Portfolio Trade Assets
In [101]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [102]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
In [103]:
MarketData.getDateRangesForStocks( ts_marketdat_mng.marketDataObj.getDataFrame() )
Out[103]:
Index Beg_Date End_Date
0 ^DJI 2000-01-03 2021-12-08
1 ^GSPC 2000-01-03 2021-12-08
2 ^IXIC 2000-01-03 2021-12-08
3 SPXL 2008-11-05 2021-12-08
4 SPXS 2008-11-19 2021-12-08
5 SDOW 2010-02-11 2021-12-08
6 SQQQ 2010-02-11 2021-12-08
7 TQQQ 2010-02-11 2021-12-08
8 UDOW 2010-02-11 2021-12-08
Simulation Broker
In [104]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [105]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [106]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio H",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1,
    
                           # Trade On ETF Params
                           trade_on_ETFs          =  True,
                           trade_assets_etf_map   = { "^DJI"  : [ "UDOW", "SDOW"], 
                                                      "^IXIC" : [ "TQQQ", "SQQQ"], 
                                                      "^GSPC" : [ "SPXL", "SPXS"] }, 
                      )
In [107]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  27
Training, Validation and Test Periods for Backtest
In [108]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2006-07-01",
                             strBegDate         = "2007-01-01",
                             strEndDate         = "2012-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2012-07-01",
                               strBegDate         = "2013-01-01",
                               strEndDate         = "2014-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2014-07-01",
                               strBegDate         = "2015-01-01",
                               strEndDate         = "2015-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
Execute Backtest
In [109]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio H",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [110]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2015-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-12-14 00:00:00 
****************

Backtest Metrics
Save to Excel
In [111]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-H backtest-metrics.xlsx")
Trade Strategies Execution & Investment Metrics

DOW Jones

In [112]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[112]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_gru_1_^DJI No 11 2000000.0 1.967475e+06 -0.016262 Completed
2 ts_lstm_^DJI No 3 2000000.0 1.923487e+06 -0.038257 Completed
3 ts_conv1d_gru_^DJI No 3 2000000.0 1.923487e+06 -0.038257 Completed
4 ts_conv1d_lstm_^DJI No 1 2000000.0 2.356786e+06 0.178393 Completed
5 ts_wavenet_^DJI No 9 2000000.0 2.451199e+06 0.225599 Completed
6 ts_wavenet_gru_^DJI No 3 2000000.0 1.926829e+06 -0.036586 Completed
7 ts_wavenet_lstm_^DJI No 1 2000000.0 2.356786e+06 0.178393 Completed
8 all_All_^DJI No 3 2000000.0 1.923487e+06 -0.038257 Completed
25 Long-Only Trade Strategy for ^DJI No 1 2000000.0 1.954308e+06 -0.022846 Completed

Nasdaq

In [113]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[113]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
9 ts_gru_1_^IXIC No 1 2000000.0 2.825457e+06 0.412728 Completed
10 ts_lstm_^IXIC No 1 2000000.0 2.825457e+06 0.412728 Completed
11 ts_conv1d_gru_^IXIC No 1 2000000.0 2.825457e+06 0.412728 Completed
12 ts_conv1d_lstm_^IXIC No 1 2000000.0 2.825457e+06 0.412728 Completed
13 ts_wavenet_^IXIC No 3 2000000.0 2.715533e+06 0.357767 Completed
14 ts_wavenet_gru_^IXIC No 1 2000000.0 2.825457e+06 0.412728 Completed
15 ts_wavenet_lstm_^IXIC No 1 2000000.0 2.825457e+06 0.412728 Completed
16 all_All_^IXIC No 1 2000000.0 2.825457e+06 0.412728 Completed
26 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.118694e+06 0.059347 Completed

S&P 500

In [114]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[114]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
17 ts_gru_1_^GSPC No 3 2000000.0 1.987484e+06 -0.006258 Completed
18 ts_lstm_^GSPC No 1 2000000.0 2.424675e+06 0.212338 Completed
19 ts_conv1d_gru_^GSPC No 1 2000000.0 2.424675e+06 0.212338 Completed
20 ts_conv1d_lstm_^GSPC No 1 2000000.0 2.424675e+06 0.212338 Completed
21 ts_wavenet_^GSPC No 13 2000000.0 1.842056e+06 -0.078972 Completed
22 ts_wavenet_gru_^GSPC No 1 2000000.0 2.424675e+06 0.212338 Completed
23 ts_wavenet_lstm_^GSPC No 1 2000000.0 2.424675e+06 0.212338 Completed
24 all_All_^GSPC No 1 2000000.0 2.424675e+06 0.212338 Completed
27 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 1.986154e+06 -0.006923 Completed
Performance Metrics
In [115]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI"' )
Out[115]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 ts_gru_1_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 -0.06 -0.06 0.09 -0.35 0.11 -0.13
2 ts_lstm_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 -0.08 -0.08 0.03 -0.41 0.11 -0.22
3 ts_conv1d_gru_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 -0.08 -0.08 0.03 -0.41 0.11 -0.22
4 ts_conv1d_lstm_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 0.13 0.13 0.49 -0.35 0.19 -0.12
5 ts_wavenet_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 0.17 0.17 0.59 -0.21 0.11 -0.13
6 ts_wavenet_gru_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 -0.08 -0.08 0.01 -0.41 0.11 -0.14
7 ts_wavenet_lstm_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 0.13 0.13 0.49 -0.35 0.19 -0.12
8 all_All_^DJI No Static ^DJI 2015-01-05 2015-12-31 0.99 -0.08 -0.08 0.03 -0.41 0.11 -0.22
25 Long-Only Trade Strategy for ^DJI No Static ^DJI 2015-01-05 2015-12-31 1.0 -0.02 -0.02 -0.07 -0.14 0.04 -0.04
In [116]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC"' )
Out[116]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
9 ts_gru_1_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.34 0.34 0.98 -0.25 0.15 -0.09
10 ts_lstm_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.34 0.34 0.98 -0.25 0.15 -0.09
11 ts_conv1d_gru_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.34 0.34 0.98 -0.25 0.15 -0.09
12 ts_conv1d_lstm_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.34 0.34 0.98 -0.25 0.15 -0.09
13 ts_wavenet_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.29 0.29 0.8 -0.32 0.14 -0.18
14 ts_wavenet_gru_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.34 0.34 0.98 -0.25 0.15 -0.09
15 ts_wavenet_lstm_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.34 0.34 0.98 -0.25 0.15 -0.09
16 all_All_^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.34 0.34 0.98 -0.25 0.15 -0.09
26 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2015-01-05 2015-12-31 1.0 0.06 0.06 0.43 -0.14 0.04 -0.04
In [117]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC"' )
Out[117]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
17 ts_gru_1_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 -0.04 -0.04 0.15 -0.38 0.1 -0.25
18 ts_lstm_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 0.17 0.17 0.58 -0.28 0.16 -0.12
19 ts_conv1d_gru_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 0.17 0.17 0.58 -0.28 0.16 -0.12
20 ts_conv1d_lstm_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 0.17 0.17 0.58 -0.28 0.16 -0.12
21 ts_wavenet_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 -0.11 -0.11 0.01 -0.38 0.12 -0.18
22 ts_wavenet_gru_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 0.17 0.17 0.58 -0.28 0.16 -0.12
23 ts_wavenet_lstm_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 0.17 0.17 0.58 -0.28 0.16 -0.12
24 all_All_^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 0.17 0.17 0.58 -0.28 0.16 -0.12
27 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2015-01-05 2015-12-31 1.0 -0.01 -0.01 0.03 -0.12 0.04 -0.04

Portfolio I

Portfolio I: Monthly Rebalance of Funds in the Portfolio

- Same strategies as defined and explained in Portfolio C.

- Only difference is the Portfolio Investment Manager is configured to balance funds monthly, 
  using an equal weights policy.

Backtest:

1. Type: regular

2. Test Period: 
    1. Begin Date = 2012-01-01 
    2. End Date   = 2015-12-31   
Portfolio Trade Assets
In [118]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [119]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [120]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [121]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : True },
                                  'exit_policy_args'   : { 'lastn_match' : 2 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : True },
                                  'exit_policy_args'   : { 'lastn_match' : 2 } },
                             },
                    }  )

# TS #3

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_3",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : True },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_4",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : True },
                                  'exit_policy_args'   : { 'lastn_match' : 2 } },
                             },
                    }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_5",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 75 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : True },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_6",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : True },
                                  'exit_policy_args'   : { 'lastn_match' : 2 } },
                             },
                    }  )

# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_7",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : True },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [122]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio I",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Monthly,
                           portfRebalancePeriods                   = 1
                      )
In [123]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  27
Execute Backtest
In [124]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio I",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2012-01-01", 
                                            strEndDate = "2015-12-31" ),
                    trade_asset_registered_item = portf_registered_obj )
In [125]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-02-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-12-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-01-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-02-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-03-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-04-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-05-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-06-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-07-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-08-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-09-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-10-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-10-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-11-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-12-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-01-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-02-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-03-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-04-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-05-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-06-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-07-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-08-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-09-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-10-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-11-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-12-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-01-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-02-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-03-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-05-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-06-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-07-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-07-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-08-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-09-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-10-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-11-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-12-22 00:00:00 
****************

Backtest Metrics
Save to Excel
In [126]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-I backtest-metrics.xlsx")
Execution & Investment Metrics
In [127]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']]
Out[127]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
0 Portfolio I Yes 825 54000000.0 5.807555e+07 0.075473 Completed
1 ts_sma_1_^DJI No 13 2000000.0 2.149857e+06 0.074929 Completed
2 ts_sma_2_^DJI No 26 2000000.0 2.149857e+06 0.074929 Completed
3 ts_sma_3_^DJI No 26 2000000.0 2.149857e+06 0.074929 Completed
4 ts_sma_4_^DJI No 24 2000000.0 2.184573e+06 0.092287 Completed
5 ts_sma_5_^DJI No 19 2000000.0 2.149857e+06 0.074929 Completed
6 ts_sma_6_^DJI No 34 2000000.0 2.149857e+06 0.074929 Completed
7 ts_sma_7_^DJI No 34 2000000.0 2.149857e+06 0.074929 Completed
8 all_All_^DJI No 53 2000000.0 2.184573e+06 0.092287 Completed
9 ts_sma_1_^IXIC No 11 2000000.0 2.149857e+06 0.074929 Completed
10 ts_sma_2_^IXIC No 23 2000000.0 2.149857e+06 0.074929 Completed
11 ts_sma_3_^IXIC No 23 2000000.0 2.149857e+06 0.074929 Completed
12 ts_sma_4_^IXIC No 16 2000000.0 2.149857e+06 0.074929 Completed
13 ts_sma_5_^IXIC No 13 2000000.0 2.149857e+06 0.074929 Completed
14 ts_sma_6_^IXIC No 36 2000000.0 2.149857e+06 0.074929 Completed
15 ts_sma_7_^IXIC No 36 2000000.0 2.149857e+06 0.074929 Completed
16 all_All_^IXIC No 57 2000000.0 2.149857e+06 0.074929 Completed
17 ts_sma_1_^GSPC No 11 2000000.0 2.149857e+06 0.074929 Completed
18 ts_sma_2_^GSPC No 32 2000000.0 2.149857e+06 0.074929 Completed
19 ts_sma_3_^GSPC No 32 2000000.0 2.149857e+06 0.074929 Completed
20 ts_sma_4_^GSPC No 22 2000000.0 2.149857e+06 0.074929 Completed
21 ts_sma_5_^GSPC No 17 2000000.0 2.149857e+06 0.074929 Completed
22 ts_sma_6_^GSPC No 36 2000000.0 2.149857e+06 0.074929 Completed
23 ts_sma_7_^GSPC No 36 2000000.0 2.149857e+06 0.074929 Completed
24 all_All_^GSPC No 54 2000000.0 2.149857e+06 0.074929 Completed
25 Long-Only Trade Strategy for ^DJI No 47 2000000.0 2.137262e+06 0.068631 Completed
26 Long-Only Trade Strategy for ^IXIC No 47 2000000.0 2.135552e+06 0.067776 Completed
27 Long-Only Trade Strategy for ^GSPC No 47 2000000.0 2.136732e+06 0.068366 Completed
Performance Metrics
In [128]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[128]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio I Yes 2012-01-04 2015-12-31 1.0 0.08 0.02 0.53 -0.1 0.01 -0.01
1 ts_sma_1_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.23 0.07 0.02 0.3 -0.11 0.07 -0.02
2 ts_sma_2_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.29 0.07 0.02 0.28 -0.09 0.04 -0.02
3 ts_sma_3_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.29 0.07 0.02 0.29 -0.09 0.04 -0.02
4 ts_sma_4_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.32 0.09 0.02 0.3 -0.1 0.05 -0.02
5 ts_sma_5_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.28 0.07 0.02 0.28 -0.09 0.05 -0.02
6 ts_sma_6_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.33 0.07 0.02 0.26 -0.12 0.05 -0.04
7 ts_sma_7_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.33 0.07 0.02 0.26 -0.12 0.04 -0.04
8 all_All_^DJI No Static ^DJI 2012-01-04 2015-12-31 0.54 0.09 0.02 0.26 -0.1 0.07 -0.04
9 ts_sma_1_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.22 0.07 0.02 0.25 -0.13 0.08 -0.04
10 ts_sma_2_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.26 0.07 0.02 0.25 -0.14 0.04 -0.05
11 ts_sma_3_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.26 0.07 0.02 0.25 -0.14 0.03 -0.05
12 ts_sma_4_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.21 0.07 0.02 0.23 -0.18 0.11 -0.08
13 ts_sma_5_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.2 0.07 0.02 0.23 -0.17 0.11 -0.08
14 ts_sma_6_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.34 0.07 0.02 0.24 -0.15 0.04 -0.04
15 ts_sma_7_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.34 0.07 0.02 0.24 -0.15 0.04 -0.04
16 all_All_^IXIC No Static ^IXIC 2012-01-04 2015-12-31 0.52 0.07 0.02 0.21 -0.16 0.06 -0.05
17 ts_sma_1_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.21 0.07 0.02 0.28 -0.12 0.08 -0.04
18 ts_sma_2_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.31 0.07 0.02 0.25 -0.12 0.06 -0.04
19 ts_sma_3_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.3 0.07 0.02 0.26 -0.11 0.05 -0.04
20 ts_sma_4_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.28 0.07 0.02 0.27 -0.11 0.04 -0.04
21 ts_sma_5_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.24 0.07 0.02 0.3 -0.12 0.04 -0.03
22 ts_sma_6_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.32 0.07 0.02 0.26 -0.16 0.04 -0.04
23 ts_sma_7_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.32 0.07 0.02 0.26 -0.15 0.06 -0.04
24 all_All_^GSPC No Static ^GSPC 2012-01-04 2015-12-31 0.49 0.07 0.02 0.23 -0.12 0.05 -0.03
25 Long-Only Trade Strategy for ^DJI No Static ^DJI 2012-01-04 2015-12-31 1.0 0.07 0.02 0.18 -0.21 0.1 -0.08
26 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2012-01-04 2015-12-31 1.0 0.07 0.02 0.18 -0.24 0.12 -0.1
27 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2012-01-04 2015-12-31 1.0 0.07 0.02 0.18 -0.21 0.09 -0.09

Portfolio J

Portfolio J: Trade Strategies with different Market Data Sources (Quandal, YahooFinance, User-Defined DataFrame)

- Futures data is sourced from Quandal (Cotton, Soy Beans, and S&P 500 futures)

- US Equity indexes from Yahoo-Finance

- Leverage ETFs TQQQ and SQQQ from the user-defined DataFrame

- Multiple SMA Models, and LSTM, GRU, MACD, and RSI Models defined to use with each trading asset

- Additionally, there is a composite trade strategy for all Futures, and one composite trade
  strategy for the US Index equities

- Buy-and-Hold strategies for each trade asset for comparison

- $2,000,000/strategy

Backtest:

1. Type: regular

2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2002-01-01 
        2. End Date   = 2006-12-31  
    2. Validation Period: 
        1. Begin Date = 2007-01-01 
        2. End Date   = 2008-12-31 

3. Test Period: 
    1. Begin Date = 2009-01-01 
    2. End Date   = 2009-12-31         
Market Data Manager - Yahoo-Finance
In [129]:
portfolio_trade_assets_yf   = [ "^DJI", "^IXIC", "^GSPC" ]
In [130]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng_yf = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Market Data Manager - From User-Defined Pandas DataFrame

User can provide their own market data via a Pandas DataFrame

Requirements:

1. DataFrame Index : must be called "Date", and be of datetime format
2. Index column : All data associated with a given trade asset. Same exact format as the 
   yahoofinance above
3. The rest of the columns in the dataframe can be named anything. However, it is recommended
   they used standard names as the ones in YahooFinance above; this will make all built-in 
   AI and Technical Analysis Models available.
4. Note, interval, supportedTradeAssets are constraint and not enforced; the data that is passed
   in the dataframe is what is supported.
In [131]:
ts_marketdat_mng_df = TradeStrategyMarketDataMng(\
        marketDataProviderName = "dataframe",
        marketDataDF           =  ts_marketdat_mng_yf.marketDataObj.getDataFrame(),                     
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_DF",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        forceCreateMarketData  = False,
        interval               = "1d"  ) 
In [132]:
ts_marketdat_mng_df.marketDataObj.getDataFrame()
Out[132]:
Index Adj Close Close High Low Next_Date Next_Period_Open Open Volume
Date
2001-01-02 ^DJI 10646.150391 10646.150391 10797.019531 10585.360352 2001-01-03 10637.419922 10790.919922 253300000
2001-01-03 ^DJI 10945.750000 10945.750000 11019.049805 10581.089844 2001-01-04 10944.940430 10637.419922 420720000
2001-01-04 ^DJI 10912.410156 10912.410156 11028.000000 10888.419922 2001-01-05 10912.809570 10944.940430 382800000
2001-01-05 ^DJI 10662.009766 10662.009766 10919.419922 10627.750000 2001-01-08 10658.730469 10912.809570 272650000
2001-01-08 ^DJI 10621.349609 10621.349609 10700.849609 10516.019531 2001-01-09 10625.209961 10658.730469 225780000
... ... ... ... ... ... ... ... ... ...
2010-12-27 SQQQ 37727.582031 39283.199219 40499.199219 39129.601562 2010-12-28 39104.000000 39692.800781 245
2010-12-28 SQQQ 37924.269531 39488.000000 39680.000000 38963.199219 2010-12-29 39180.800781 39104.000000 88
2010-12-29 SQQQ 37702.992188 39257.601562 39334.398438 39014.398438 2010-12-30 39206.398438 39180.800781 102
2010-12-30 SQQQ 37961.148438 39526.398438 39731.199219 39206.398438 2010-12-31 39680.000000 39206.398438 137
2010-12-31 SQQQ 38329.941406 39910.398438 40422.398438 39577.601562 2010-12-31 38329.941406 39680.000000 182

9521 rows × 9 columns

Market Data Manager - Quandal

Download the following data from Quandal:

  1. CHRIS/CME_S2
  2. CHRIS/ICE_CT1
  3. CHRIS/CME_SP1

    Where CHRIS is the Quandal Data Provider, and the name after the / is the Futures symbol.

    The format of the JSON to download from Quandal is:

    { quandal-path :

       [ description of data, 
         [ columns to extract from the returned Quandal DataFrame ], 
         { "Quandal_Column" : "Rename Quandal Column" } 
       ]
    

    }

Note:

1. The nested dictionary to rename the original downloaded Quandal data, it is provided since Quandal does
   not have standard output column names.  
       - Futures data from different data sources might have different returned column names for the same
         state, that is "Close" vs. "close", etc.
       - For sharing the same market data manager object it is recommended to rename the columns to have 
         standard names, and match the ones provided by Yahoo Finance

2. Yahoo Finance returns standard equity column names

3. All implemented AI and Technical Models used standard column names (same as Yahoo Finance)
   Columns: Adj Close, Close, Open, High, Low, Volume
   Index: Datetime

4. In order to use the implemented models the Quandal Market Data or any Custom Market Data must have
   similar named columns, or the user can implement his own models and use whatever column names he/she
   prefers.

5. In this example, the Quandal data source does not provide all standard column names, only open,
   which is re-named to 'Adj Close'.  Therefore only some of the built models will be available,
   as they required High, Low, such as Bollinger Bands
In [133]:
indexQuantCodeMap = { 
       "CHRIS/CME_S2"  : ["SoyBeans", ["Open", "Volume"],  { "Open" : "Adj Close" } ],
       "CHRIS/ICE_CT1" : ["Cotton",   ["Open", "Volume"],  { "Open" : "Adj Close" } ],
       "CHRIS/CME_SP1" : ["S&P_500",  ["Open", "Volume"],  { "Open" : "Adj Close" } ]  }

portfolio_trade_assets_quandal = list ( indexQuantCodeMap.keys()  )
In [134]:
dirPathMarketDataQuandl = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/TSMarketDat'

beg_date_for_feature_creation = "2000-10-01"
beg_date_str                  = "2001-01-01"
end_date_str                  = "2010-12-31"

ts_marketdat_mng_quandal = TradeStrategyMarketDataMng(\
        marketDataProviderName = "quandl",
        supportedTradeAssets   = portfolio_trade_assets_quandal,   
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "Quandl_Test_1_PorfolioRegisterItem_Portf_J",
        dirPathMarketData      = dirPathMarketDataQuandl,
        beg_date_str           = beg_date_for_feature_creation,
        end_date_str           = end_date_str,
        interval               = "1d" ,
        updateDataPassEndDate  = False,
        forceCreateMarketData  = False,
        indexQuantCodeMap      = indexQuantCodeMap, # required for quandl market data provider, defined above
        # The Quandal provider used does not return Open, High, Low, Close, so map the "Adj Close" column
        # to all standard columns in order to utilized some of the models that required that data (ATR, etc.)
        create_std_ohlc_cols_dict = { "Open" : "Adj Close", "Low" : "Adj Close",
                                      "High" : "Adj Close", "Close" : "Adj Close" }
        ) 
In [135]:
ts_marketdat_mng_quandal.marketDataObj.getDataFrame()
Out[135]:
Index Index_Name Provider Adj Close Volume Open Low High Close Next_Period_Open Next_Date
Date
2000-10-02 CHRIS/CME_S2 SoyBeans Quandl 498.0 4183.0 498.0 498.0 498.0 498.0 499.0 2000-10-03
2000-10-03 CHRIS/CME_S2 SoyBeans Quandl 499.0 4324.0 499.0 499.0 499.0 499.0 499.0 2000-10-04
2000-10-04 CHRIS/CME_S2 SoyBeans Quandl 499.0 5863.0 499.0 499.0 499.0 499.0 494.0 2000-10-05
2000-10-05 CHRIS/CME_S2 SoyBeans Quandl 494.0 5153.0 494.0 494.0 494.0 494.0 494.5 2000-10-06
2000-10-06 CHRIS/CME_S2 SoyBeans Quandl 494.5 4432.0 494.5 494.5 494.5 494.5 494.0 2000-10-09
... ... ... ... ... ... ... ... ... ... ... ...
2010-12-27 CHRIS/CME_SP1 S&P_500 Quandl 1249.7 5943.0 1249.7 1249.7 1249.7 1249.7 1253.4 2010-12-28
2010-12-28 CHRIS/CME_SP1 S&P_500 Quandl 1253.4 4358.0 1253.4 1253.4 1253.4 1253.4 1253.5 2010-12-29
2010-12-29 CHRIS/CME_SP1 S&P_500 Quandl 1253.5 5845.0 1253.5 1253.5 1253.5 1253.5 1255.7 2010-12-30
2010-12-30 CHRIS/CME_SP1 S&P_500 Quandl 1255.7 5876.0 1255.7 1255.7 1255.7 1255.7 1254.5 2010-12-31
2010-12-31 CHRIS/CME_SP1 S&P_500 Quandl 1254.5 10650.0 1254.5 1254.5 1254.5 1254.5 1254.5 2010-12-31

7540 rows × 11 columns

Simulation Broker
In [136]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [137]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #3

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_3",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_4",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_5",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 75 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_6",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_7",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 12, 'win_slow' : 40 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #8

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #9

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_macd",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 26, 'window_fast' : 12, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #11

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_rsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "rsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'rsi_enter_long'  : 30.0,  'rsi_exit_long'  : 30.0, 
                                                 'rsi_enter_short' : 70.0,  'rsi_exit_short' : 70.0 },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [138]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItemForMarketDataMngs(
           name_ta_reg_item        = "Portfolio J",

           # *** Trade Assets & Market Data Managers
           market_data_mngs        = { "yf"      : [ portfolio_trade_assets_yf, ts_marketdat_mng_yf,
                                                     MarketDataPeriod.Day ],
                                       "quandal" : [ portfolio_trade_assets_quandal, ts_marketdat_mng_quandal,
                                                     MarketDataPeriod.Day ],
                                       "custom1" : [ portfolio_trade_assets_yf, ts_marketdat_mng_df,
                                                     MarketDataPeriod.Day ],
                                     },
           dirPathMarketData       = dirPathMarketData,

           # *** Broker
           brokerTradingObj        = brokerTradingObj,

           # *** T.S. Permutations for each of the following sets of models
           enter_exit_config_models = tsConfDat,

           # *** Investment Manager Params 
           minPeriodsBetweenTrades                 = 1,
           initInvestmentPerTradeStrategy          = 2000000.0, 
           capPercentToInvestPerTrade              = 100.0,
           minInvestPercent                        = 5.0,
           enter_trade_next_open_period            = True,
           min_account_balance                     = 1000.0,
           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
           portfRebalancePeriods                   = 1
        )
In [139]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  114
Training, Validation and Test Periods for Backtest
In [140]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2001-07-01",
                             strBegDate         = "2002-01-01",
                             strEndDate         = "2006-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2006-07-01",
                               strBegDate         = "2007-01-01",
                               strEndDate         = "2008-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2008-07-01",
                               strBegDate         = "2009-01-01",
                               strEndDate         = "2009-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
Execute Backtest
In [141]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio J",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [142]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************

Backtest Metrics
Save to Excel
In [143]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-J backtest-metrics.xlsx")
Execution & Investment Metrics
In [144]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("CHRIS")', engine='python')
Out[144]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
37 ts_sma_1_CHRIS/CME_S2 No 6 2000000.0 1272129.00 -0.363936 Completed
38 ts_sma_2_CHRIS/CME_S2 No 7 2000000.0 1646778.50 -0.176611 Completed
39 ts_sma_3_CHRIS/CME_S2 No 7 2000000.0 1646778.50 -0.176611 Completed
40 ts_sma_4_CHRIS/CME_S2 No 5 2000000.0 1638159.00 -0.180921 Completed
41 ts_sma_5_CHRIS/CME_S2 No 6 2000000.0 1285228.00 -0.357386 Completed
42 ts_sma_6_CHRIS/CME_S2 No 8 2000000.0 1699315.00 -0.150342 Completed
43 ts_sma_7_CHRIS/CME_S2 No 7 2000000.0 2008164.00 0.004082 Completed
44 ts_gru_CHRIS/CME_S2 No 67 2000000.0 1983973.00 -0.008013 Completed
45 ts_lstm_CHRIS/CME_S2 No 49 2000000.0 2104987.50 0.052494 Completed
46 ts_macd_CHRIS/CME_S2 No 22 2000000.0 1954989.50 -0.022505 Completed
47 ts_rsi_CHRIS/CME_S2 No 9 2000000.0 2067851.00 0.033925 Completed
48 all_All_CHRIS/CME_S2 No 10 2000000.0 1877107.50 -0.061446 Completed
49 ts_sma_1_CHRIS/ICE_CT1 No 2 2000000.0 3184348.33 0.592174 Completed
50 ts_sma_2_CHRIS/ICE_CT1 No 7 2000000.0 1746050.02 -0.126975 Completed
51 ts_sma_3_CHRIS/ICE_CT1 No 7 2000000.0 1746050.02 -0.126975 Completed
52 ts_sma_4_CHRIS/ICE_CT1 No 6 2000000.0 2253046.92 0.126523 Completed
53 ts_sma_5_CHRIS/ICE_CT1 No 6 2000000.0 2400358.53 0.200179 Completed
54 ts_sma_6_CHRIS/ICE_CT1 No 7 2000000.0 2047259.36 0.023630 Completed
55 ts_sma_7_CHRIS/ICE_CT1 No 7 2000000.0 1407448.56 -0.296276 Completed
56 ts_gru_CHRIS/ICE_CT1 No 57 2000000.0 2586900.94 0.293450 Completed
57 ts_lstm_CHRIS/ICE_CT1 No 53 2000000.0 2862366.89 0.431183 Completed
58 ts_macd_CHRIS/ICE_CT1 No 24 2000000.0 1917943.04 -0.041028 Completed
59 ts_rsi_CHRIS/ICE_CT1 No 7 2000000.0 2143423.31 0.071712 Completed
60 all_All_CHRIS/ICE_CT1 No 11 2000000.0 2045304.90 0.022652 Completed
61 ts_sma_1_CHRIS/CME_SP1 No 2 2000000.0 2902103.10 0.451052 Completed
62 ts_sma_2_CHRIS/CME_SP1 No 6 2000000.0 2206415.50 0.103208 Completed
63 ts_sma_3_CHRIS/CME_SP1 No 6 2000000.0 2206415.50 0.103208 Completed
64 ts_sma_4_CHRIS/CME_SP1 No 6 2000000.0 2588083.90 0.294042 Completed
65 ts_sma_5_CHRIS/CME_SP1 No 2 2000000.0 2881113.80 0.440557 Completed
66 ts_sma_6_CHRIS/CME_SP1 No 7 2000000.0 2086956.70 0.043478 Completed
67 ts_sma_7_CHRIS/CME_SP1 No 7 2000000.0 2119056.60 0.059528 Completed
68 ts_gru_CHRIS/CME_SP1 No 45 2000000.0 2655275.60 0.327638 Completed
69 ts_lstm_CHRIS/CME_SP1 No 35 2000000.0 2525063.80 0.262532 Completed
70 ts_macd_CHRIS/CME_SP1 No 31 2000000.0 1739941.20 -0.130029 Completed
71 ts_rsi_CHRIS/CME_SP1 No 11 2000000.0 2133863.30 0.066932 Completed
72 all_All_CHRIS/CME_SP1 No 8 2000000.0 2355273.90 0.177637 Completed
110 Long-Only Trade Strategy for CHRIS/CME_S2 No 1 2000000.0 2164880.00 0.082440 Completed
113 Long-Only Trade Strategy for CHRIS/CME_SP1 No 1 2000000.0 2495507.50 0.247754 Completed
114 Long-Only Trade Strategy for CHRIS/ICE_CT1 No 1 2000000.0 3065580.16 0.532790 Completed
Performance Metrics
In [145]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'model_type', 'trade_asset', 'Start Period', 'End Period', 'Time in Market ',
   'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[145]:
ta_reg_item_name is_portfolio model_type trade_asset Start Period End Period Time in Market Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 Portfolio J Yes 2009-01-05 2009-12-31 1.0 0.1 0.1 1.08 -0.06 0.02 -0.02
1 ts_sma_1_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.39 0.4 1.76 -0.15 0.04 -0.05
2 ts_sma_2_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.2 0.2 0.93 -0.14 0.05 -0.05
3 ts_sma_3_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.2 0.2 0.93 -0.14 0.05 -0.05
4 ts_sma_4_^DJI No Static ^DJI 2009-01-05 2009-12-31 1.0 0.23 0.24 1.12 -0.18 0.04 -0.05
... ... ... ... ... ... ... ... ... ... ... ... ... ...
110 Long-Only Trade Strategy for CHRIS/CME_S2 No Static CHRIS/CME_S2 2009-01-05 2009-12-31 0.98 0.08 0.08 0.41 -0.25 0.06 -0.08
111 Long-Only Trade Strategy for ^GSPC No Static ^GSPC 2009-01-05 2009-12-31 1.0 0.2 0.2 0.8 -0.28 0.07 -0.05
112 Long-Only Trade Strategy for ^IXIC No Static ^IXIC 2009-01-05 2009-12-31 1.0 0.39 0.4 1.32 -0.23 0.07 -0.06
113 Long-Only Trade Strategy for CHRIS/CME_SP1 No Static CHRIS/CME_SP1 2009-01-05 2009-12-31 1.0 0.25 0.25 0.98 -0.27 0.07 -0.05
114 Long-Only Trade Strategy for CHRIS/ICE_CT1 No Static CHRIS/ICE_CT1 2009-01-05 2009-12-31 1.0 0.53 0.54 1.47 -0.23 0.12 -0.07

115 rows × 13 columns

Portfolio K

  1. Portfolio K: Long and Multiple Configured SMA Trade Strategies for US Indixes, with Stop Models

    Description:

     1. Seven distinct SMA Trade Strategies for enter/exit a trade, plus an ensemble trade strategy
        of all seven SMA models
     2. Eight different stop-models
         1. Stop Loss order with specified stop-loss percent limit 
         2. Trail Stop Loss order with specified trail-stop-loss percent limit 
         3. Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
         4-8. Five different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived
             stop-loss and trail-stop-loss percent limits using Average True Range(ATR) algorithm
     3. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Backtest:

     1. Type: regular
     2. Test Period: 
         1. Begin Date = 2001-01-01 
         2. End Date   = 2020-12-31 
Portfolio Trade Assets
In [146]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [147]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        forceCreateMarketData  = False,
        interval               = "1d"  ) 
Simulation Broker
In [148]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [149]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )


# TS #3


tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_3",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 57 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_4",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_5",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 75 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_6",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_7",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 12, 'win_slow' : 40 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )
Risk-Stop-Loss Models
In [150]:
# ***
# *** Configure Several Types of Stop Actions
# ***
#      order_type = 1 ( Stop-Loss )
#      order_type = 2 ( Trail-Stop-Loss )
#      order_type = 3 ( Combine Stop-Loss & Trail-Stop-Loss )
#
# Stop Models :
#       fixval { user-defined stop-loss-percent and/or trail-stop-loss-percent }
#       atr    { uses ATR model to dynamically determined the stop and trail stop loss percents }

# 1) *** Stop-Loss Order Type

tsStopsConfDat_Stop_Loss = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 1 } }
           } )
           
tsStopsConfDat_Stop_Loss.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# 2) *** Trail-Stop-Loss Order Type

tsStopsConfDat_Trail_Stop_Loss = TradeStrategyConfigData()

tsStopsConfDat_Trail_Stop_Loss.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 2} }
           } )
           
tsStopsConfDat_Trail_Stop_Loss.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# 3) *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Fixed Values

tsStopsConfDat_Stop_Loss_And_Trail_SL_1 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_1.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_1.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# 4) *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Dynamic Values from ATR

tsStopsConfDat_Stop_Loss_And_Trail_SL_2 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_2.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_2.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_1",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 14, 
                                                 'stop_loss_mult'          : 0.5,
                                                 'trail_stop_loss_mult'    : 1.0,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.002,
                                                 'max_trail_stop_loss_per' : 0.05,
                                                 'min_trail_stop_loss_per' : 0.005,
                                               },
                                },
                             },
                   }  )

# 5) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_3 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_3.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_3.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_2",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                               },
                                },
                             },
                   }  )

# 6) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_4 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_4.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_4.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_3",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.01,
                                                 'trail_stop_loss_mult'    : 0.03,
                                               },
                                },
                             },
                   }  )

# 7) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_5 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_5.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_5.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_4",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                                 'max_stop_loss_per'       : 0.005,
                                                 'min_stop_loss_per'       : 0.002,
                                                 'max_trail_stop_loss_per' : 0.005,
                                                 'min_trail_stop_loss_per' : 0.002,
                                               },
                                },
                             },
                   }  )

# 8) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_6 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_6.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_6.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_5",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                                 'max_stop_loss_per'       : 0.005,
                                                 'min_stop_loss_per'       : 0.002,
                                                 'max_trail_stop_loss_per' : 0.01,
                                                 'min_trail_stop_loss_per' : 0.005,
                                               },
                                },
                             },
                   }  )
stopsConfDatList = [ tsStopsConfDat_Stop_Loss,                tsStopsConfDat_Trail_Stop_Loss,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_1, tsStopsConfDat_Stop_Loss_And_Trail_SL_2,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_3, tsStopsConfDat_Stop_Loss_And_Trail_SL_4,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_5, tsStopsConfDat_Stop_Loss_And_Trail_SL_6
                   ]
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [151]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio K",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,
                           stop_config_models       = stopsConfDatList,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [152]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  219
Execute Backtest
In [153]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio K",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2001-01-01", 
                                            strEndDate = "2020-12-31" ),
                    trade_asset_registered_item = portf_registered_obj )
In [154]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-02-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-02-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-02-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-04-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-05-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-07-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-08-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-09-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-10-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-11-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-12-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-02-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-04-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-05-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-06-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-07-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-08-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-09-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-11-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-12-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-02-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-02-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-04-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-05-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-07-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-08-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-09-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-10-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-11-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-12-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-02-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-03-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-04-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-05-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-06-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-07-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-09-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-10-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-11-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-12-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-01-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-02-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-03-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-04-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-05-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-05-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-06-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-07-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-08-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-09-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-10-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-11-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-12-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-01-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-02-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-03-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-04-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-05-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-06-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-07-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-08-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-09-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-10-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-10-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-12-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-12-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-01-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-02-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-03-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-05-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-12-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-01-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-02-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-03-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-05-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-06-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-07-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-08-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-08-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-09-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-10-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-11-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-12-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-01-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-02-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-03-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-04-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-05-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-06-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-07-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-08-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-09-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-10-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-11-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-12-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-01-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-02-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-03-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-04-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-05-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-05-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-06-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-07-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-08-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-12-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-01-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-02-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-03-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-04-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-05-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-06-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-07-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-08-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-09-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-10-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-11-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-12-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-12-14 00:00:00 
****************

Backtest Metrics
Save to Excel
In [155]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-K backtest-metrics.xlsx")
Execution & Investment Metrics

DOW

In [156]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[156]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_sma_1_^DJI No 74 2000000.0 1.303695e+06 -0.348152 Completed
2 ts_sma_2_^DJI No 122 2000000.0 2.315659e+06 0.157830 Completed
3 ts_sma_3_^DJI No 117 2000000.0 2.023809e+06 0.011904 Completed
4 ts_sma_4_^DJI No 97 2000000.0 2.116670e+06 0.058335 Completed
5 ts_sma_5_^DJI No 85 2000000.0 2.431389e+06 0.215695 Completed
... ... ... ... ... ... ... ...
197 ts_sma_5_sl_tsl_atr_5_^DJI No 3312 2000000.0 3.331307e+08 165.565329 Completed
198 ts_sma_6_sl_tsl_atr_5_^DJI No 3385 2000000.0 1.966187e+08 97.309374 Completed
199 ts_sma_7_sl_tsl_atr_5_^DJI No 3379 2000000.0 2.136470e+08 105.823516 Completed
200 all_All_sl_tsl_atr_5_^DJI No 3335 2000000.0 2.545980e+08 126.299001 Completed
217 Long-Only Trade Strategy for ^DJI No 1 2000000.0 5.732582e+06 1.866291 Completed

73 rows × 7 columns

Nasdaq

In [157]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[157]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
9 ts_sma_1_^IXIC No 68 2000000.0 1.862317e+06 -0.068841 Completed
10 ts_sma_2_^IXIC No 120 2000000.0 4.860321e+06 1.430160 Completed
11 ts_sma_3_^IXIC No 112 2000000.0 4.809255e+06 1.404627 Completed
12 ts_sma_4_^IXIC No 90 2000000.0 5.337433e+06 1.668717 Completed
13 ts_sma_5_^IXIC No 76 2000000.0 5.976039e+06 1.988019 Completed
... ... ... ... ... ... ... ...
205 ts_sma_5_sl_tsl_atr_5_^IXIC No 3575 2000000.0 4.851659e+07 23.258293 Completed
206 ts_sma_6_sl_tsl_atr_5_^IXIC No 3661 2000000.0 2.257552e+07 10.287762 Completed
207 ts_sma_7_sl_tsl_atr_5_^IXIC No 3628 2000000.0 3.326813e+07 15.634064 Completed
208 all_All_sl_tsl_atr_5_^IXIC No 3584 2000000.0 4.329163e+07 20.645814 Completed
218 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 1.124008e+07 4.620039 Completed

73 rows × 7 columns

S&P 500

In [158]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[158]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
17 ts_sma_1_^GSPC No 58 2000000.0 2.594762e+06 0.297381 Completed
18 ts_sma_2_^GSPC No 133 2000000.0 1.970411e+06 -0.014794 Completed
19 ts_sma_3_^GSPC No 116 2000000.0 2.247404e+06 0.123702 Completed
20 ts_sma_4_^GSPC No 108 2000000.0 3.827821e+06 0.913911 Completed
21 ts_sma_5_^GSPC No 76 2000000.0 4.568023e+06 1.284012 Completed
... ... ... ... ... ... ... ...
213 ts_sma_5_sl_tsl_atr_5_^GSPC No 3287 2000000.0 3.318833e+08 164.941643 Completed
214 ts_sma_6_sl_tsl_atr_5_^GSPC No 3380 2000000.0 1.927005e+08 95.350249 Completed
215 ts_sma_7_sl_tsl_atr_5_^GSPC No 3361 2000000.0 1.784473e+08 88.223665 Completed
216 all_All_sl_tsl_atr_5_^GSPC No 3312 2000000.0 2.472669e+08 122.633457 Completed
219 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 5.852622e+06 1.926311 Completed

73 rows × 7 columns

Portfolio L

  1. Portfolio L: Long and Multiple Configured TA Trade Strategies for US Indixes, with Stop Models

    Description:

     1. Eleven distinct TA Trade Strategies for enter/exit a trade, plus an ensemble trade strategy
        of all eleven TA models
     2. Five different stop-models
         1. Stop Loss order with specified stop-loss percent limit 
         2. Trail Stop Loss order with specified trail-stop-loss percent limit 
         3. Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
         4-5. Three different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived
             stop-loss and trail-stop-loss percent limits using Average True Range(ATR) algorithm
     3. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Backtest:

     1. Type: regular
     2. Test Period: 
         1. Begin Date = 2001-01-01 
         2. End Date   = 2020-12-31 
Portfolio Trade Assets
In [159]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [160]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        forceCreateMarketData  = False,
        interval               = "1d"  ) 
Simulation Broker
In [161]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [162]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )          
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #3

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_bb",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "bb",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 13, 'window_dev' : 1 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_macd",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 26, 'window_fast' : 12, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_rsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "rsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'rsi_enter_long'  : 30.0,  'rsi_exit_long'  : 30.0, 
                                                 'rsi_enter_short' : 70.0,  'rsi_exit_short' : 70.0 },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_srsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "srsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 14,  'smooth1' : 3, 'smooth2'  : 3,
                                                 'srsi_enter_long'  : 0.8,  'srsi_exit_long'  : 0.8,
                                                 'srsi_enter_short' : 0.2,  'srsi_exit_short' : 0.2 },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_adx",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "adx",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'adx_enter_long_ge' : 14, 'adx_exit_long_lt'  : 14,
                                             'adx_enter_short_ge' : 14, 'adx_exit_short_lt' : 14 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #8

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #9

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_forceindex",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "forceindex",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 39 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #11

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_mfi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "mfi",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'long_slope_win' : 15, 'short_slope_win' : 15 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
Risk-Stop-Loss Models
In [163]:
# ***
# *** Configure Several Types of Stop Actions
# ***
#      order_type = 1 ( Stop-Loss )
#      order_type = 2 ( Trail-Stop-Loss )
#      order_type = 3 ( Combine Stop-Loss & Trail-Stop-Loss )
#
# Stop Models :
#       fixval { user-defined stop-loss-percent and/or trail-stop-loss-percent }
#       atr    { uses ATR model to dynamically determined the stop and trail stop loss percents }

# *** Stop-Loss Order Type

tsStopsConfDat_Stop_Loss = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 1 } }
           } )
           
tsStopsConfDat_Stop_Loss.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# *** Trail-Stop-Loss Order Type

tsStopsConfDat_Trail_Stop_Loss = TradeStrategyConfigData()

tsStopsConfDat_Trail_Stop_Loss.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 2} }
           } )
           
tsStopsConfDat_Trail_Stop_Loss.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Fixed Values

tsStopsConfDat_Stop_Loss_And_Trail_SL_1 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_1.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_1.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_3 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_3.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_3.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_2",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                               },
                                },
                             },
                   }  )

# ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_4 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_4.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_4.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_3",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.01,
                                                 'trail_stop_loss_mult'    : 0.03,
                                               },
                                },
                             },
                   }  )


stopsConfDatList = [ tsStopsConfDat_Stop_Loss, tsStopsConfDat_Trail_Stop_Loss,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_1, tsStopsConfDat_Stop_Loss_And_Trail_SL_3,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_4
                   ]
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [164]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio L",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,
                           stop_config_models       = stopsConfDatList,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [165]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  219
Execute Backtest
In [166]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio L",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2001-01-01", 
                                            strEndDate = "2020-12-31" ),
                    trade_asset_registered_item = portf_registered_obj )
In [167]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-02-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-02-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-02-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-04-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-05-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-07-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-08-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-09-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-10-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-11-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-12-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-02-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-04-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-05-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-06-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-07-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-08-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-09-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-11-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-12-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-02-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-02-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-04-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-05-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-07-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-08-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-09-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-10-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-11-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-12-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-02-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-03-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-04-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-05-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-06-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-07-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-09-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-10-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-11-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-12-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-01-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-02-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-03-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-04-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-05-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-05-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-06-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-07-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-08-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-09-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-10-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-11-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-12-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-01-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-02-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-03-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-04-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-05-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-06-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-07-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-08-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-09-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-10-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-10-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-12-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-12-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-01-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-02-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-03-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-05-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-12-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-01-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-02-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-03-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-05-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-06-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-07-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-08-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-08-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-09-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-10-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-11-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-12-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-01-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-02-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-03-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-04-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-05-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-06-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-07-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-08-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-09-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-10-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-11-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-12-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-01-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-02-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-03-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-04-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-05-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-05-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-06-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-07-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-08-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-12-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-01-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-02-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-03-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-04-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-05-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-06-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-07-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-08-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-09-09 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-10-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-11-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-12-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-12-14 00:00:00 
****************

Backtest Metrics
Save to Excel
In [168]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-L backtest-metrics.xlsx")
Execution & Investment Metrics

DOW

In [169]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[169]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_sma_1_^DJI No 123 2000000.0 2.685115e+06 0.342558 Completed
2 ts_sma_2_^DJI No 97 2000000.0 2.116670e+06 0.058335 Completed
3 ts_bb_^DJI No 880 2000000.0 2.469612e+06 0.234806 Completed
4 ts_macd_^DJI No 401 2000000.0 3.905481e+06 0.952741 Completed
5 ts_rsi_^DJI No 132 2000000.0 3.021183e+06 0.510592 Completed
... ... ... ... ... ... ... ...
189 ts_tsi_sl_tsl_atr_3_^DJI No 4354 2000000.0 2.576464e+09 1287.231760 Completed
190 ts_forceindex_sl_tsl_atr_3_^DJI No 4371 2000000.0 2.006271e+09 1002.135585 Completed
191 ts_mfi_sl_tsl_atr_3_^DJI No 2742 2000000.0 2.536427e+08 125.821340 Completed
192 all_All_sl_tsl_atr_3_^DJI No 4262 2000000.0 2.048416e+09 1023.208186 Completed
217 Long-Only Trade Strategy for ^DJI No 1 2000000.0 5.732582e+06 1.866291 Completed

73 rows × 7 columns

Nasdaq

In [170]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[170]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
13 ts_sma_1_^IXIC No 122 2000000.0 3.596705e+06 0.798353 Completed
14 ts_sma_2_^IXIC No 90 2000000.0 5.337433e+06 1.668717 Completed
15 ts_bb_^IXIC No 824 2000000.0 2.947387e+06 0.473694 Completed
16 ts_macd_^IXIC No 416 2000000.0 1.309714e+06 -0.345143 Completed
17 ts_rsi_^IXIC No 159 2000000.0 4.667740e+06 1.333870 Completed
... ... ... ... ... ... ... ...
201 ts_tsi_sl_tsl_atr_3_^IXIC No 4773 2000000.0 1.649152e+07 7.245760 Completed
202 ts_forceindex_sl_tsl_atr_3_^IXIC No 4783 2000000.0 1.354595e+07 5.772973 Completed
203 ts_mfi_sl_tsl_atr_3_^IXIC No 2939 2000000.0 5.848251e+06 1.924126 Completed
204 all_All_sl_tsl_atr_3_^IXIC No 4661 2000000.0 1.471908e+07 6.359542 Completed
218 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 1.124008e+07 4.620039 Completed

73 rows × 7 columns

S&P 500

In [171]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[171]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
25 ts_sma_1_^GSPC No 136 2000000.0 1.560453e+06 -0.219773 Completed
26 ts_sma_2_^GSPC No 108 2000000.0 3.827821e+06 0.913911 Completed
27 ts_bb_^GSPC No 874 2000000.0 3.925487e+06 0.962743 Completed
28 ts_macd_^GSPC No 425 2000000.0 1.853421e+06 -0.073290 Completed
29 ts_rsi_^GSPC No 154 2000000.0 3.711187e+06 0.855594 Completed
... ... ... ... ... ... ... ...
213 ts_tsi_sl_tsl_atr_3_^GSPC No 4340 2000000.0 2.768806e+09 1383.403196 Completed
214 ts_forceindex_sl_tsl_atr_3_^GSPC No 4353 2000000.0 2.123452e+09 1060.725838 Completed
215 ts_mfi_sl_tsl_atr_3_^GSPC No 2785 2000000.0 2.418877e+08 119.943830 Completed
216 all_All_sl_tsl_atr_3_^GSPC No 4249 2000000.0 2.229888e+09 1113.943877 Completed
219 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 5.852622e+06 1.926311 Completed

73 rows × 7 columns

Portfolio M

  1. Portfolio M: Long and Multiple Configured AI Trade Strategies for US Indixes, with Stop Models

    Description:

     1. Eight distinct AI Trade Strategies for enter/exit a trade, plus an ensemble trade strategy
        of all AI models
     2. Four different stop-models
         1. Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
         2-4. Three different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived
              stop-loss and trail-stop-loss percent limits using Average True Range(ATR) algorithm
     3. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Backtest:

     1. Type: regular
     2. AI Models Fit Date Ranges
         1. Training Period: 
             1. Begin Date = 2002-01-01 
             2. End Date   = 2006-12-31  
         2. Validation Period: 
             1. Begin Date = 2007-01-01 
             2. End Date   = 2008-12-31   
     4. Test Period: 
         1. Begin Date = 2009-01-01 
         2. End Date   = 2009-12-31 
Portfolio Trade Assets
In [172]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [173]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [174]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [175]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )
Risk-Stop-Loss Models
In [176]:
# ***
# *** Configure Several Types of Stop Actions
# ***
#      order_type = 1 ( Stop-Loss )
#      order_type = 2 ( Trail-Stop-Loss )
#      order_type = 3 ( Combine Stop-Loss & Trail-Stop-Loss )
#
# Stop Models :
#       fixval { user-defined stop-loss-percent and/or trail-stop-loss-percent }
#       atr    { uses ATR model to dynamically determined the stop and trail stop loss percents }

# *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Fixed Values

tsStopsConfDat_Stop_Loss_And_Trail_SL_1 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_1.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_1.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Dynamic Values from ATR

tsStopsConfDat_Stop_Loss_And_Trail_SL_2 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_2.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_2.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_1",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 14, 
                                                 'stop_loss_mult'          : 0.5,
                                                 'trail_stop_loss_mult'    : 1.0,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.002,
                                                 'max_trail_stop_loss_per' : 0.05,
                                                 'min_trail_stop_loss_per' : 0.005,
                                               },
                                },
                             },
                   }  )

# ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_3 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_3.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_3.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_2",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                               },
                                },
                             },
                   }  )

# ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_4 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_4.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_4.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_3",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.01,
                                                 'trail_stop_loss_mult'    : 0.03,
                                               },
                                },
                             },
                   }  )


stopsConfDatList = [ tsStopsConfDat_Stop_Loss_And_Trail_SL_1, tsStopsConfDat_Stop_Loss_And_Trail_SL_2,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_3, tsStopsConfDat_Stop_Loss_And_Trail_SL_4,
                   ]
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [177]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio M",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,
                           stop_config_models       = stopsConfDatList,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [178]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  138
Execute Backtest
In [179]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2001-07-01",
                             strBegDate         = "2002-01-01",
                             strEndDate         = "2006-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2006-07-01",
                               strBegDate         = "2007-01-01",
                               strEndDate         = "2008-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2008-07-01",
                               strBegDate         = "2009-01-01",
                               strEndDate         = "2009-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
In [180]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio M",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [181]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************

Backtest Metrics
In [182]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-M backtest-metrics.xlsx")
Execution & Investment Metrics

DOW

In [183]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[183]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_gru_1_^DJI No 56 2000000.0 2.768343e+06 0.384172 Completed
2 ts_lstm_^DJI No 52 2000000.0 2.336025e+06 0.168013 Completed
3 ts_conv1d_gru_^DJI No 60 2000000.0 2.061737e+06 0.030868 Completed
4 ts_conv1d_lstm_^DJI No 52 2000000.0 2.826407e+06 0.413204 Completed
5 ts_wavenet_^DJI No 46 2000000.0 2.185845e+06 0.092923 Completed
6 ts_wavenet_gru_^DJI No 52 2000000.0 2.293320e+06 0.146660 Completed
7 ts_wavenet_lstm_^DJI No 70 2000000.0 2.215337e+06 0.107668 Completed
8 ts_gru_2_^DJI No 56 2000000.0 2.768343e+06 0.384172 Completed
9 all_All_^DJI No 60 2000000.0 2.733866e+06 0.366933 Completed
28 ts_gru_1_sl_tsl_fixval_^DJI No 224 2000000.0 3.437795e+06 0.718897 Completed
29 ts_lstm_sl_tsl_fixval_^DJI No 224 2000000.0 3.354004e+06 0.677002 Completed
30 ts_conv1d_gru_sl_tsl_fixval_^DJI No 222 2000000.0 3.068669e+06 0.534335 Completed
31 ts_conv1d_lstm_sl_tsl_fixval_^DJI No 220 2000000.0 3.614556e+06 0.807278 Completed
32 ts_wavenet_sl_tsl_fixval_^DJI No 218 2000000.0 3.456466e+06 0.728233 Completed
33 ts_wavenet_gru_sl_tsl_fixval_^DJI No 221 2000000.0 3.537232e+06 0.768616 Completed
34 ts_wavenet_lstm_sl_tsl_fixval_^DJI No 228 2000000.0 3.494939e+06 0.747469 Completed
35 ts_gru_2_sl_tsl_fixval_^DJI No 224 2000000.0 3.437795e+06 0.718897 Completed
36 all_All_sl_tsl_fixval_^DJI No 205 2000000.0 3.334115e+06 0.667058 Completed
55 ts_gru_1_sl_tsl_atr_1_^DJI No 133 2000000.0 2.912235e+06 0.456118 Completed
56 ts_lstm_sl_tsl_atr_1_^DJI No 134 2000000.0 2.924144e+06 0.462072 Completed
57 ts_conv1d_gru_sl_tsl_atr_1_^DJI No 143 2000000.0 2.457635e+06 0.228818 Completed
58 ts_conv1d_lstm_sl_tsl_atr_1_^DJI No 128 2000000.0 3.284873e+06 0.642436 Completed
59 ts_wavenet_sl_tsl_atr_1_^DJI No 127 2000000.0 2.694546e+06 0.347273 Completed
60 ts_wavenet_gru_sl_tsl_atr_1_^DJI No 133 2000000.0 2.787212e+06 0.393606 Completed
61 ts_wavenet_lstm_sl_tsl_atr_1_^DJI No 147 2000000.0 3.052063e+06 0.526032 Completed
62 ts_gru_2_sl_tsl_atr_1_^DJI No 133 2000000.0 2.912235e+06 0.456118 Completed
63 all_All_sl_tsl_atr_1_^DJI No 131 2000000.0 3.129607e+06 0.564803 Completed
82 ts_gru_1_sl_tsl_atr_2_^DJI No 229 2000000.0 3.458722e+06 0.729361 Completed
83 ts_lstm_sl_tsl_atr_2_^DJI No 232 2000000.0 3.391789e+06 0.695895 Completed
84 ts_conv1d_gru_sl_tsl_atr_2_^DJI No 230 2000000.0 3.077655e+06 0.538827 Completed
85 ts_conv1d_lstm_sl_tsl_atr_2_^DJI No 227 2000000.0 3.695898e+06 0.847949 Completed
86 ts_wavenet_sl_tsl_atr_2_^DJI No 226 2000000.0 3.556589e+06 0.778295 Completed
87 ts_wavenet_gru_sl_tsl_atr_2_^DJI No 226 2000000.0 3.700969e+06 0.850485 Completed
88 ts_wavenet_lstm_sl_tsl_atr_2_^DJI No 231 2000000.0 3.574499e+06 0.787250 Completed
89 ts_gru_2_sl_tsl_atr_2_^DJI No 229 2000000.0 3.458722e+06 0.729361 Completed
90 all_All_sl_tsl_atr_2_^DJI No 208 2000000.0 3.342411e+06 0.671206 Completed
109 ts_gru_1_sl_tsl_atr_3_^DJI No 235 2000000.0 3.878335e+06 0.939168 Completed
110 ts_lstm_sl_tsl_atr_3_^DJI No 237 2000000.0 3.783403e+06 0.891701 Completed
111 ts_conv1d_gru_sl_tsl_atr_3_^DJI No 235 2000000.0 3.410140e+06 0.705070 Completed
112 ts_conv1d_lstm_sl_tsl_atr_3_^DJI No 235 2000000.0 4.055147e+06 1.027574 Completed
113 ts_wavenet_sl_tsl_atr_3_^DJI No 230 2000000.0 3.839186e+06 0.919593 Completed
114 ts_wavenet_gru_sl_tsl_atr_3_^DJI No 234 2000000.0 4.077475e+06 1.038738 Completed
115 ts_wavenet_lstm_sl_tsl_atr_3_^DJI No 235 2000000.0 3.851715e+06 0.925857 Completed
116 ts_gru_2_sl_tsl_atr_3_^DJI No 235 2000000.0 3.878335e+06 0.939168 Completed
117 all_All_sl_tsl_atr_3_^DJI No 214 2000000.0 3.653268e+06 0.826634 Completed
136 Long-Only Trade Strategy for ^DJI No 1 2000000.0 2.307932e+06 0.153966 Completed

Nasdaq

In [184]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[184]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
10 ts_gru_1_^IXIC No 48 2000000.0 1.374006e+06 -0.312997 Completed
11 ts_lstm_^IXIC No 33 2000000.0 1.412792e+06 -0.293604 Completed
12 ts_conv1d_gru_^IXIC No 40 2000000.0 1.374142e+06 -0.312929 Completed
13 ts_conv1d_lstm_^IXIC No 56 2000000.0 2.215471e+06 0.107735 Completed
14 ts_wavenet_^IXIC No 41 2000000.0 1.793882e+06 -0.103059 Completed
15 ts_wavenet_gru_^IXIC No 38 2000000.0 2.215847e+06 0.107923 Completed
16 ts_wavenet_lstm_^IXIC No 72 2000000.0 2.389811e+06 0.194906 Completed
17 ts_gru_2_^IXIC No 48 2000000.0 1.374006e+06 -0.312997 Completed
18 all_All_^IXIC No 51 2000000.0 1.446419e+06 -0.276791 Completed
37 ts_gru_1_sl_tsl_fixval_^IXIC No 220 2000000.0 2.574157e+06 0.287078 Completed
38 ts_lstm_sl_tsl_fixval_^IXIC No 217 2000000.0 2.340757e+06 0.170379 Completed
39 ts_conv1d_gru_sl_tsl_fixval_^IXIC No 221 2000000.0 2.264732e+06 0.132366 Completed
40 ts_conv1d_lstm_sl_tsl_fixval_^IXIC No 220 2000000.0 2.680489e+06 0.340244 Completed
41 ts_wavenet_sl_tsl_fixval_^IXIC No 217 2000000.0 2.624493e+06 0.312247 Completed
42 ts_wavenet_gru_sl_tsl_fixval_^IXIC No 214 2000000.0 2.568533e+06 0.284266 Completed
43 ts_wavenet_lstm_sl_tsl_fixval_^IXIC No 230 2000000.0 2.321369e+06 0.160685 Completed
44 ts_gru_2_sl_tsl_fixval_^IXIC No 220 2000000.0 2.574157e+06 0.287078 Completed
45 all_All_sl_tsl_fixval_^IXIC No 211 2000000.0 2.519260e+06 0.259630 Completed
64 ts_gru_1_sl_tsl_atr_1_^IXIC No 139 2000000.0 1.747359e+06 -0.126320 Completed
65 ts_lstm_sl_tsl_atr_1_^IXIC No 131 2000000.0 1.624869e+06 -0.187566 Completed
66 ts_conv1d_gru_sl_tsl_atr_1_^IXIC No 137 2000000.0 1.668837e+06 -0.165582 Completed
67 ts_conv1d_lstm_sl_tsl_atr_1_^IXIC No 138 2000000.0 2.272021e+06 0.136011 Completed
68 ts_wavenet_sl_tsl_atr_1_^IXIC No 138 2000000.0 1.987088e+06 -0.006456 Completed
69 ts_wavenet_gru_sl_tsl_atr_1_^IXIC No 127 2000000.0 2.015794e+06 0.007897 Completed
70 ts_wavenet_lstm_sl_tsl_atr_1_^IXIC No 150 2000000.0 2.092774e+06 0.046387 Completed
71 ts_gru_2_sl_tsl_atr_1_^IXIC No 139 2000000.0 1.747359e+06 -0.126320 Completed
72 all_All_sl_tsl_atr_1_^IXIC No 139 2000000.0 1.809533e+06 -0.095234 Completed
91 ts_gru_1_sl_tsl_atr_2_^IXIC No 228 2000000.0 2.755770e+06 0.377885 Completed
92 ts_lstm_sl_tsl_atr_2_^IXIC No 224 2000000.0 2.511077e+06 0.255539 Completed
93 ts_conv1d_gru_sl_tsl_atr_2_^IXIC No 230 2000000.0 2.419734e+06 0.209867 Completed
94 ts_conv1d_lstm_sl_tsl_atr_2_^IXIC No 228 2000000.0 2.790221e+06 0.395111 Completed
95 ts_wavenet_sl_tsl_atr_2_^IXIC No 228 2000000.0 2.820743e+06 0.410371 Completed
96 ts_wavenet_gru_sl_tsl_atr_2_^IXIC No 225 2000000.0 2.703595e+06 0.351797 Completed
97 ts_wavenet_lstm_sl_tsl_atr_2_^IXIC No 237 2000000.0 2.447861e+06 0.223931 Completed
98 ts_gru_2_sl_tsl_atr_2_^IXIC No 228 2000000.0 2.755770e+06 0.377885 Completed
99 all_All_sl_tsl_atr_2_^IXIC No 217 2000000.0 2.692459e+06 0.346229 Completed
118 ts_gru_1_sl_tsl_atr_3_^IXIC No 240 2000000.0 2.579220e+06 0.289610 Completed
119 ts_lstm_sl_tsl_atr_3_^IXIC No 239 2000000.0 2.332071e+06 0.166035 Completed
120 ts_conv1d_gru_sl_tsl_atr_3_^IXIC No 244 2000000.0 2.141094e+06 0.070547 Completed
121 ts_conv1d_lstm_sl_tsl_atr_3_^IXIC No 241 2000000.0 2.419212e+06 0.209606 Completed
122 ts_wavenet_sl_tsl_atr_3_^IXIC No 241 2000000.0 2.560239e+06 0.280120 Completed
123 ts_wavenet_gru_sl_tsl_atr_3_^IXIC No 238 2000000.0 2.495893e+06 0.247946 Completed
124 ts_wavenet_lstm_sl_tsl_atr_3_^IXIC No 245 2000000.0 2.409852e+06 0.204926 Completed
125 ts_gru_2_sl_tsl_atr_3_^IXIC No 240 2000000.0 2.579220e+06 0.289610 Completed
126 all_All_sl_tsl_atr_3_^IXIC No 227 2000000.0 2.406663e+06 0.203331 Completed
137 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.780251e+06 0.390126 Completed

S&P 500

In [185]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[185]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
19 ts_gru_1_^GSPC No 16 2000000.0 2.001147e+06 0.000574 Completed
20 ts_lstm_^GSPC No 21 2000000.0 1.689975e+06 -0.155012 Completed
21 ts_conv1d_gru_^GSPC No 30 2000000.0 2.595040e+06 0.297520 Completed
22 ts_conv1d_lstm_^GSPC No 3 2000000.0 2.498398e+06 0.249199 Completed
23 ts_wavenet_^GSPC No 6 2000000.0 2.068429e+06 0.034215 Completed
24 ts_wavenet_gru_^GSPC No 12 2000000.0 2.207892e+06 0.103946 Completed
25 ts_wavenet_lstm_^GSPC No 13 2000000.0 2.363158e+06 0.181579 Completed
26 ts_gru_2_^GSPC No 16 2000000.0 2.001147e+06 0.000574 Completed
27 all_All_^GSPC No 15 2000000.0 1.993714e+06 -0.003143 Completed
46 ts_gru_1_sl_tsl_fixval_^GSPC No 209 2000000.0 3.082490e+06 0.541245 Completed
47 ts_lstm_sl_tsl_fixval_^GSPC No 212 2000000.0 2.874819e+06 0.437410 Completed
48 ts_conv1d_gru_sl_tsl_fixval_^GSPC No 209 2000000.0 3.265227e+06 0.632613 Completed
49 ts_conv1d_lstm_sl_tsl_fixval_^GSPC No 207 2000000.0 2.860394e+06 0.430197 Completed
50 ts_wavenet_sl_tsl_fixval_^GSPC No 204 2000000.0 2.955167e+06 0.477584 Completed
51 ts_wavenet_gru_sl_tsl_fixval_^GSPC No 203 2000000.0 2.973392e+06 0.486696 Completed
52 ts_wavenet_lstm_sl_tsl_fixval_^GSPC No 202 2000000.0 3.094352e+06 0.547176 Completed
53 ts_gru_2_sl_tsl_fixval_^GSPC No 209 2000000.0 3.082490e+06 0.541245 Completed
54 all_All_sl_tsl_fixval_^GSPC No 176 2000000.0 2.796792e+06 0.398396 Completed
73 ts_gru_1_sl_tsl_atr_1_^GSPC No 110 2000000.0 2.071436e+06 0.035718 Completed
74 ts_lstm_sl_tsl_atr_1_^GSPC No 113 2000000.0 2.010410e+06 0.005205 Completed
75 ts_conv1d_gru_sl_tsl_atr_1_^GSPC No 108 2000000.0 2.930391e+06 0.465196 Completed
76 ts_conv1d_lstm_sl_tsl_atr_1_^GSPC No 95 2000000.0 2.349679e+06 0.174840 Completed
77 ts_wavenet_sl_tsl_atr_1_^GSPC No 88 2000000.0 2.241007e+06 0.120504 Completed
78 ts_wavenet_gru_sl_tsl_atr_1_^GSPC No 90 2000000.0 2.446072e+06 0.223036 Completed
79 ts_wavenet_lstm_sl_tsl_atr_1_^GSPC No 86 2000000.0 2.669887e+06 0.334944 Completed
80 ts_gru_2_sl_tsl_atr_1_^GSPC No 110 2000000.0 2.071436e+06 0.035718 Completed
81 all_All_sl_tsl_atr_1_^GSPC No 96 2000000.0 2.191393e+06 0.095696 Completed
100 ts_gru_1_sl_tsl_atr_2_^GSPC No 220 2000000.0 3.594373e+06 0.797187 Completed
101 ts_lstm_sl_tsl_atr_2_^GSPC No 224 2000000.0 3.258460e+06 0.629230 Completed
102 ts_conv1d_gru_sl_tsl_atr_2_^GSPC No 221 2000000.0 3.618100e+06 0.809050 Completed
103 ts_conv1d_lstm_sl_tsl_atr_2_^GSPC No 220 2000000.0 3.194067e+06 0.597033 Completed
104 ts_wavenet_sl_tsl_atr_2_^GSPC No 215 2000000.0 3.210522e+06 0.605261 Completed
105 ts_wavenet_gru_sl_tsl_atr_2_^GSPC No 212 2000000.0 3.364137e+06 0.682069 Completed
106 ts_wavenet_lstm_sl_tsl_atr_2_^GSPC No 211 2000000.0 3.425928e+06 0.712964 Completed
107 ts_gru_2_sl_tsl_atr_2_^GSPC No 220 2000000.0 3.594373e+06 0.797187 Completed
108 all_All_sl_tsl_atr_2_^GSPC No 183 2000000.0 3.011842e+06 0.505921 Completed
127 ts_gru_1_sl_tsl_atr_3_^GSPC No 224 2000000.0 3.987737e+06 0.993868 Completed
128 ts_lstm_sl_tsl_atr_3_^GSPC No 228 2000000.0 3.695806e+06 0.847903 Completed
129 ts_conv1d_gru_sl_tsl_atr_3_^GSPC No 223 2000000.0 4.005270e+06 1.002635 Completed
130 ts_conv1d_lstm_sl_tsl_atr_3_^GSPC No 223 2000000.0 3.558637e+06 0.779318 Completed
131 ts_wavenet_sl_tsl_atr_3_^GSPC No 220 2000000.0 3.545450e+06 0.772725 Completed
132 ts_wavenet_gru_sl_tsl_atr_3_^GSPC No 216 2000000.0 3.760791e+06 0.880396 Completed
133 ts_wavenet_lstm_sl_tsl_atr_3_^GSPC No 214 2000000.0 3.804585e+06 0.902292 Completed
134 ts_gru_2_sl_tsl_atr_3_^GSPC No 224 2000000.0 3.987737e+06 0.993868 Completed
135 all_All_sl_tsl_atr_3_^GSPC No 187 2000000.0 3.318636e+06 0.659318 Completed
138 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 2.393362e+06 0.196681 Completed

Portfolio N

  1. Portfolio N: Long and Multiple Configured AI Trade Strategies for US Indixes, with Stop Models

    Description:

     1. Eight distinct AI Trade Strategies for enter/exit a trade, plus an ensemble trade strategy
        of all AI models
     2. Five different stop-models
             Different Combine Stop-Loss & Trail-Stop-Loss models, configured with AI derived
             stop-loss and trail-stop-loss percent limits using LSTM, GRU, etc. time series models to
             forecast next day True Range for the stock, and use that information to derive the percent
             stop limits.
             The Stop-Models in this Portfolio are AI based, unlike the ones in Portfolio K, which are
             based on the Technical Indicator, Average True Range (ATR)
     3. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Backtest:

     1. Type: regular
     2. AI Models Fit Date Ranges
         1. Training Period: 
             1. Begin Date = 2002-01-01 
             2. End Date   = 2006-12-31  
         2. Validation Period: 
             1. Begin Date = 2007-01-01 
             2. End Date   = 2008-12-31   
     4. Test Period: 
         1. Begin Date = 2009-01-01 
         2. End Date   = 2009-12-31 
Portfolio Trade Assets
In [186]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]
Market Data Manager
In [187]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [188]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Models
In [189]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )
                            
Risk-Stop-Loss Models
In [190]:
##### ***
# *** Configure Several Types of Stop Actions
# ***
#      order_type = 1 ( Stop-Loss )
#      order_type = 2 ( Trail-Stop-Loss )
#      order_type = 3 ( Combine Stop-Loss & Trail-Stop-Loss )
#
# Stop Models :
#       ai_true_range  { - uses an AI model to predict the next's day True-Range, the underlying
#                          predicting AI Model can vary, in this example, two models use LSTM, and
#                          another one uses xxx. 
#                        - the ai_true_range model applies rules and constraints to the predicted true
#                          range, and derives the stop_loss and trail_stop_loss percent limits for the trade.
#                      }

ai_model_x_features = ['Adj Close', 'Volume', 'true_range', 'true_range_vol1'  ]

# AI Stop Model #1 (using LSTM for predicting next day True Range)

tsStopsConfDat_Stop_Loss_And_Trail_SL_1 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_1.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
        
tsStopsConfDat_Stop_Loss_And_Trail_SL_1.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_ai_tr_1",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "ai_true_range",
                                  'ai_model' : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.0001,
                                                 'max_trail_stop_loss_per' : 0.07,
                                                 'min_trail_stop_loss_per' : 0.0001,
                                               },
                                  'ai_obj_args' : { 'n_steps'         : 5,   'no_neurons_lay1'    : 20,
                                                    'no_neurons_lay2' : 20,   'pred_ahead_periods' : 1,
                                                    'epochs'          : 20,
                                                    'features'        : ai_model_x_features,
                                                    'features_label'  : 'true_range'
                                                  }  
                                },
                             },
                   }  )

# AI Stop Model #2 (using LSTM for predicting next day True Range)
#     -> diff, stop loss and trail loss multiplier, slightly smaller than model #1

tsStopsConfDat_Stop_Loss_And_Trail_SL_2 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_2.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
        
tsStopsConfDat_Stop_Loss_And_Trail_SL_2.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_ai_tr_2",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "ai_true_range",
                                  'ai_model' : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'stop_loss_mult'          : 0.01,
                                                 'trail_stop_loss_mult'    : 0.03,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.0001,
                                                 'max_trail_stop_loss_per' : 0.07,
                                                 'min_trail_stop_loss_per' : 0.0001,
                                               },
                                  'ai_obj_args' : { 'n_steps'         : 10,   'no_neurons_lay1'    : 20,
                                                    'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                    'epochs'          : 20,
                                                    'features'        : ai_model_x_features,
                                                    'features_label'  : 'true_range'
                                                  }  
                                },
                             },
                   }  )

# AI Stop Model #3 (using LSTM for predicting next day True Range)
#     -> diff, stop loss and trail loss multiplier, bigger than model #1 and #2

tsStopsConfDat_Stop_Loss_And_Trail_SL_3 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_3.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
        
tsStopsConfDat_Stop_Loss_And_Trail_SL_3.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_ai_tr_3",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "ai_true_range",
                                  'ai_model' : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'stop_loss_mult'          : 0.1,
                                                 'trail_stop_loss_mult'    : 0.125,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.0001,
                                                 'max_trail_stop_loss_per' : 0.07,
                                                 'min_trail_stop_loss_per' : 0.0001,
                                               },
                                  'ai_obj_args' : { 'n_steps'         : 10,   'no_neurons_lay1'    : 20,
                                                    'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                    'epochs'          : 20,
                                                    'features'        : ai_model_x_features,
                                                    'features_label'  : 'true_range'
                                                  }  
                                },
                             },
                   }  )

# AI Stop Model #4 (using conv1d_gru for predicting next day True Range)
#     -> diff, stop loss and trail loss multiplier, bigger than model #1 and #2

tsStopsConfDat_Stop_Loss_And_Trail_SL_4 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_4.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )

tsStopsConfDat_Stop_Loss_And_Trail_SL_4.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_ai_tr_4",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "ai_true_range",
                                  'ai_model' : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'stop_loss_mult'          : 0.01,
                                                 'trail_stop_loss_mult'    : 0.03,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.0001,
                                                 'max_trail_stop_loss_per' : 0.07,
                                                 'min_trail_stop_loss_per' : 0.0001,
                                               },
                                  'ai_obj_args' : { 'n_steps'         : 20,   'no_neurons_lay1'    : 20,
                                                    'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                    'epochs'          : 20,
                                                    'features'        : ai_model_x_features,
                                                    'features_label'  : 'true_range'
                                                  }  
                                },
                             },
                   }  )

# AI Stop Model #5 (using conv1d_gru for predicting next day True Range)
#     -> diff, stop loss and trail loss multiplier, bigger than model #1 and #2

tsStopsConfDat_Stop_Loss_And_Trail_SL_5 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_5.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )

tsStopsConfDat_Stop_Loss_And_Trail_SL_5.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_ai_tr_5",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "ai_true_range",
                                  'ai_model' : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'stop_loss_mult'          : 0.03,
                                                 'trail_stop_loss_mult'    : 0.05,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.0001,
                                                 'max_trail_stop_loss_per' : 0.07,
                                                 'min_trail_stop_loss_per' : 0.0001,
                                               },
                                  'ai_obj_args' : { 'n_steps'         : 20,   'no_neurons_lay1'    : 20,
                                                    'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                    'epochs'          : 20,
                                                    'features'        : ai_model_x_features,
                                                    'features_label'  : 'true_range'
                                                  }  
                                },
                             },
                   }  )


stopsConfDatList = [ tsStopsConfDat_Stop_Loss_And_Trail_SL_1, tsStopsConfDat_Stop_Loss_And_Trail_SL_2,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_3, tsStopsConfDat_Stop_Loss_And_Trail_SL_4,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_5 ]
Trade Strategies, Trade Investment Manager, and Trade Asset Register Items
In [191]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio N",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,
                           stop_config_models       = stopsConfDatList,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [192]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  165
Execute Backtest
In [193]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2001-07-01",
                             strBegDate         = "2002-01-01",
                             strEndDate         = "2006-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2006-07-01",
                               strBegDate         = "2007-01-01",
                               strEndDate         = "2008-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2008-07-01",
                               strBegDate         = "2009-01-01",
                               strEndDate         = "2009-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )
In [194]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Portfolio N",
                    timePeriod  = testing_period,
                    fitDatasets = fit_datasets,
                    trade_asset_registered_item = portf_registered_obj )
In [195]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************

Backtest Metrics
Save to Excel
In [196]:
tsExecuteEngine.getSummaryMetrics().to_excel("Portfolio-N backtest-metrics.xlsx")
Execution & Investment Metrics

DOW

In [197]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[197]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_gru_1_^DJI No 56 2000000.0 2.768343e+06 0.384172 Completed
2 ts_lstm_^DJI No 52 2000000.0 2.336025e+06 0.168013 Completed
3 ts_conv1d_gru_^DJI No 60 2000000.0 2.061737e+06 0.030868 Completed
4 ts_conv1d_lstm_^DJI No 52 2000000.0 2.826407e+06 0.413204 Completed
5 ts_wavenet_^DJI No 46 2000000.0 2.185845e+06 0.092923 Completed
6 ts_wavenet_gru_^DJI No 52 2000000.0 2.293320e+06 0.146660 Completed
7 ts_wavenet_lstm_^DJI No 70 2000000.0 2.215337e+06 0.107668 Completed
8 ts_gru_2_^DJI No 56 2000000.0 2.768343e+06 0.384172 Completed
9 all_All_^DJI No 60 2000000.0 2.733866e+06 0.366933 Completed
28 ts_gru_1_sl_tsl_ai_tr_1_^DJI No 225 2000000.0 3.438147e+06 0.719073 Completed
29 ts_lstm_sl_tsl_ai_tr_1_^DJI No 227 2000000.0 3.317937e+06 0.658969 Completed
30 ts_conv1d_gru_sl_tsl_ai_tr_1_^DJI No 223 2000000.0 3.096822e+06 0.548411 Completed
31 ts_conv1d_lstm_sl_tsl_ai_tr_1_^DJI No 221 2000000.0 3.655952e+06 0.827976 Completed
32 ts_wavenet_sl_tsl_ai_tr_1_^DJI No 219 2000000.0 3.471464e+06 0.735732 Completed
33 ts_wavenet_gru_sl_tsl_ai_tr_1_^DJI No 223 2000000.0 3.622475e+06 0.811237 Completed
34 ts_wavenet_lstm_sl_tsl_ai_tr_1_^DJI No 228 2000000.0 3.547673e+06 0.773837 Completed
35 ts_gru_2_sl_tsl_ai_tr_1_^DJI No 225 2000000.0 3.438147e+06 0.719073 Completed
36 all_All_sl_tsl_ai_tr_1_^DJI No 206 2000000.0 3.331021e+06 0.665511 Completed
55 ts_gru_1_sl_tsl_ai_tr_2_^DJI No 233 2000000.0 3.846904e+06 0.923452 Completed
56 ts_lstm_sl_tsl_ai_tr_2_^DJI No 235 2000000.0 3.759993e+06 0.879997 Completed
57 ts_conv1d_gru_sl_tsl_ai_tr_2_^DJI No 234 2000000.0 3.386797e+06 0.693398 Completed
58 ts_conv1d_lstm_sl_tsl_ai_tr_2_^DJI No 233 2000000.0 4.023161e+06 1.011581 Completed
59 ts_wavenet_sl_tsl_ai_tr_2_^DJI No 230 2000000.0 3.805335e+06 0.902667 Completed
60 ts_wavenet_gru_sl_tsl_ai_tr_2_^DJI No 232 2000000.0 4.088242e+06 1.044121 Completed
61 ts_wavenet_lstm_sl_tsl_ai_tr_2_^DJI No 234 2000000.0 3.853253e+06 0.926626 Completed
62 ts_gru_2_sl_tsl_ai_tr_2_^DJI No 233 2000000.0 3.846904e+06 0.923452 Completed
63 all_All_sl_tsl_ai_tr_2_^DJI No 212 2000000.0 3.624745e+06 0.812373 Completed
82 ts_gru_1_sl_tsl_ai_tr_3_^DJI No 216 2000000.0 3.411927e+06 0.705963 Completed
83 ts_lstm_sl_tsl_ai_tr_3_^DJI No 216 2000000.0 3.355093e+06 0.677546 Completed
84 ts_conv1d_gru_sl_tsl_ai_tr_3_^DJI No 213 2000000.0 3.069598e+06 0.534799 Completed
85 ts_conv1d_lstm_sl_tsl_ai_tr_3_^DJI No 212 2000000.0 3.758298e+06 0.879149 Completed
86 ts_wavenet_sl_tsl_ai_tr_3_^DJI No 208 2000000.0 3.601439e+06 0.800720 Completed
87 ts_wavenet_gru_sl_tsl_ai_tr_3_^DJI No 216 2000000.0 3.503198e+06 0.751599 Completed
88 ts_wavenet_lstm_sl_tsl_ai_tr_3_^DJI No 223 2000000.0 3.526552e+06 0.763276 Completed
89 ts_gru_2_sl_tsl_ai_tr_3_^DJI No 216 2000000.0 3.411927e+06 0.705963 Completed
90 all_All_sl_tsl_ai_tr_3_^DJI No 197 2000000.0 3.411120e+06 0.705560 Completed
109 ts_gru_1_sl_tsl_ai_tr_4_^DJI No 232 2000000.0 3.808470e+06 0.904235 Completed
110 ts_lstm_sl_tsl_ai_tr_4_^DJI No 234 2000000.0 3.756318e+06 0.878159 Completed
111 ts_conv1d_gru_sl_tsl_ai_tr_4_^DJI No 234 2000000.0 3.373790e+06 0.686895 Completed
112 ts_conv1d_lstm_sl_tsl_ai_tr_4_^DJI No 232 2000000.0 4.019023e+06 1.009511 Completed
113 ts_wavenet_sl_tsl_ai_tr_4_^DJI No 230 2000000.0 3.792232e+06 0.896116 Completed
114 ts_wavenet_gru_sl_tsl_ai_tr_4_^DJI No 231 2000000.0 4.083260e+06 1.041630 Completed
115 ts_wavenet_lstm_sl_tsl_ai_tr_4_^DJI No 233 2000000.0 3.850784e+06 0.925392 Completed
116 ts_gru_2_sl_tsl_ai_tr_4_^DJI No 232 2000000.0 3.808470e+06 0.904235 Completed
117 all_All_sl_tsl_ai_tr_4_^DJI No 212 2000000.0 3.621213e+06 0.810607 Completed
136 ts_gru_1_sl_tsl_ai_tr_5_^DJI No 226 2000000.0 3.487202e+06 0.743601 Completed
137 ts_lstm_sl_tsl_ai_tr_5_^DJI No 228 2000000.0 3.247287e+06 0.623644 Completed
138 ts_conv1d_gru_sl_tsl_ai_tr_5_^DJI No 225 2000000.0 2.989002e+06 0.494501 Completed
139 ts_conv1d_lstm_sl_tsl_ai_tr_5_^DJI No 222 2000000.0 3.544877e+06 0.772438 Completed
140 ts_wavenet_sl_tsl_ai_tr_5_^DJI No 221 2000000.0 3.506707e+06 0.753353 Completed
141 ts_wavenet_gru_sl_tsl_ai_tr_5_^DJI No 224 2000000.0 3.714939e+06 0.857469 Completed
142 ts_wavenet_lstm_sl_tsl_ai_tr_5_^DJI No 229 2000000.0 3.595140e+06 0.797570 Completed
143 ts_gru_2_sl_tsl_ai_tr_5_^DJI No 226 2000000.0 3.487202e+06 0.743601 Completed
144 all_All_sl_tsl_ai_tr_5_^DJI No 207 2000000.0 3.383671e+06 0.691836 Completed
163 Long-Only Trade Strategy for ^DJI No 1 2000000.0 2.307932e+06 0.153966 Completed

Nasdaq

In [198]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[198]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
10 ts_gru_1_^IXIC No 48 2000000.0 1.374006e+06 -0.312997 Completed
11 ts_lstm_^IXIC No 33 2000000.0 1.412792e+06 -0.293604 Completed
12 ts_conv1d_gru_^IXIC No 40 2000000.0 1.374142e+06 -0.312929 Completed
13 ts_conv1d_lstm_^IXIC No 56 2000000.0 2.215471e+06 0.107735 Completed
14 ts_wavenet_^IXIC No 41 2000000.0 1.793882e+06 -0.103059 Completed
15 ts_wavenet_gru_^IXIC No 38 2000000.0 2.215847e+06 0.107923 Completed
16 ts_wavenet_lstm_^IXIC No 72 2000000.0 2.389811e+06 0.194906 Completed
17 ts_gru_2_^IXIC No 48 2000000.0 1.374006e+06 -0.312997 Completed
18 all_All_^IXIC No 51 2000000.0 1.446419e+06 -0.276791 Completed
37 ts_gru_1_sl_tsl_ai_tr_1_^IXIC No 224 2000000.0 2.492945e+06 0.246473 Completed
38 ts_lstm_sl_tsl_ai_tr_1_^IXIC No 218 2000000.0 2.308372e+06 0.154186 Completed
39 ts_conv1d_gru_sl_tsl_ai_tr_1_^IXIC No 225 2000000.0 2.185166e+06 0.092583 Completed
40 ts_conv1d_lstm_sl_tsl_ai_tr_1_^IXIC No 224 2000000.0 2.612158e+06 0.306079 Completed
41 ts_wavenet_sl_tsl_ai_tr_1_^IXIC No 221 2000000.0 2.620579e+06 0.310290 Completed
42 ts_wavenet_gru_sl_tsl_ai_tr_1_^IXIC No 216 2000000.0 2.565949e+06 0.282974 Completed
43 ts_wavenet_lstm_sl_tsl_ai_tr_1_^IXIC No 234 2000000.0 2.299098e+06 0.149549 Completed
44 ts_gru_2_sl_tsl_ai_tr_1_^IXIC No 224 2000000.0 2.492945e+06 0.246473 Completed
45 all_All_sl_tsl_ai_tr_1_^IXIC No 214 2000000.0 2.474239e+06 0.237120 Completed
64 ts_gru_1_sl_tsl_ai_tr_2_^IXIC No 236 2000000.0 2.643703e+06 0.321851 Completed
65 ts_lstm_sl_tsl_ai_tr_2_^IXIC No 235 2000000.0 2.427445e+06 0.213722 Completed
66 ts_conv1d_gru_sl_tsl_ai_tr_2_^IXIC No 240 2000000.0 2.192396e+06 0.096198 Completed
67 ts_conv1d_lstm_sl_tsl_ai_tr_2_^IXIC No 238 2000000.0 2.533902e+06 0.266951 Completed
68 ts_wavenet_sl_tsl_ai_tr_2_^IXIC No 238 2000000.0 2.683682e+06 0.341841 Completed
69 ts_wavenet_gru_sl_tsl_ai_tr_2_^IXIC No 235 2000000.0 2.592530e+06 0.296265 Completed
70 ts_wavenet_lstm_sl_tsl_ai_tr_2_^IXIC No 243 2000000.0 2.426193e+06 0.213096 Completed
71 ts_gru_2_sl_tsl_ai_tr_2_^IXIC No 236 2000000.0 2.643703e+06 0.321851 Completed
72 all_All_sl_tsl_ai_tr_2_^IXIC No 225 2000000.0 2.521449e+06 0.260724 Completed
91 ts_gru_1_sl_tsl_ai_tr_3_^IXIC No 210 2000000.0 2.223987e+06 0.111993 Completed
92 ts_lstm_sl_tsl_ai_tr_3_^IXIC No 207 2000000.0 2.017336e+06 0.008668 Completed
93 ts_conv1d_gru_sl_tsl_ai_tr_3_^IXIC No 215 2000000.0 1.851585e+06 -0.074208 Completed
94 ts_conv1d_lstm_sl_tsl_ai_tr_3_^IXIC No 211 2000000.0 2.332681e+06 0.166340 Completed
95 ts_wavenet_sl_tsl_ai_tr_3_^IXIC No 210 2000000.0 2.365550e+06 0.182775 Completed
96 ts_wavenet_gru_sl_tsl_ai_tr_3_^IXIC No 205 2000000.0 2.227963e+06 0.113982 Completed
97 ts_wavenet_lstm_sl_tsl_ai_tr_3_^IXIC No 223 2000000.0 2.032007e+06 0.016004 Completed
98 ts_gru_2_sl_tsl_ai_tr_3_^IXIC No 210 2000000.0 2.223987e+06 0.111993 Completed
99 all_All_sl_tsl_ai_tr_3_^IXIC No 202 2000000.0 2.156913e+06 0.078457 Completed
118 ts_gru_1_sl_tsl_ai_tr_4_^IXIC No 240 2000000.0 2.462230e+06 0.231115 Completed
119 ts_lstm_sl_tsl_ai_tr_4_^IXIC No 238 2000000.0 2.331048e+06 0.165524 Completed
120 ts_conv1d_gru_sl_tsl_ai_tr_4_^IXIC No 243 2000000.0 2.121547e+06 0.060774 Completed
121 ts_conv1d_lstm_sl_tsl_ai_tr_4_^IXIC No 242 2000000.0 2.371156e+06 0.185578 Completed
122 ts_wavenet_sl_tsl_ai_tr_4_^IXIC No 240 2000000.0 2.565869e+06 0.282935 Completed
123 ts_wavenet_gru_sl_tsl_ai_tr_4_^IXIC No 238 2000000.0 2.496824e+06 0.248412 Completed
124 ts_wavenet_lstm_sl_tsl_ai_tr_4_^IXIC No 245 2000000.0 2.382526e+06 0.191263 Completed
125 ts_gru_2_sl_tsl_ai_tr_4_^IXIC No 240 2000000.0 2.462230e+06 0.231115 Completed
126 all_All_sl_tsl_ai_tr_4_^IXIC No 227 2000000.0 2.401248e+06 0.200624 Completed
145 ts_gru_1_sl_tsl_ai_tr_5_^IXIC No 228 2000000.0 2.720727e+06 0.360363 Completed
146 ts_lstm_sl_tsl_ai_tr_5_^IXIC No 224 2000000.0 2.484686e+06 0.242343 Completed
147 ts_conv1d_gru_sl_tsl_ai_tr_5_^IXIC No 229 2000000.0 2.371152e+06 0.185576 Completed
148 ts_conv1d_lstm_sl_tsl_ai_tr_5_^IXIC No 228 2000000.0 2.734342e+06 0.367171 Completed
149 ts_wavenet_sl_tsl_ai_tr_5_^IXIC No 228 2000000.0 2.788275e+06 0.394137 Completed
150 ts_wavenet_gru_sl_tsl_ai_tr_5_^IXIC No 225 2000000.0 2.672731e+06 0.336365 Completed
151 ts_wavenet_lstm_sl_tsl_ai_tr_5_^IXIC No 237 2000000.0 2.449052e+06 0.224526 Completed
152 ts_gru_2_sl_tsl_ai_tr_5_^IXIC No 228 2000000.0 2.720727e+06 0.360363 Completed
153 all_All_sl_tsl_ai_tr_5_^IXIC No 217 2000000.0 2.662121e+06 0.331061 Completed
164 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.780251e+06 0.390126 Completed

S&P 500

In [199]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[199]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
19 ts_gru_1_^GSPC No 16 2000000.0 2.001147e+06 0.000574 Completed
20 ts_lstm_^GSPC No 21 2000000.0 1.689975e+06 -0.155012 Completed
21 ts_conv1d_gru_^GSPC No 30 2000000.0 2.595040e+06 0.297520 Completed
22 ts_conv1d_lstm_^GSPC No 3 2000000.0 2.498398e+06 0.249199 Completed
23 ts_wavenet_^GSPC No 6 2000000.0 2.068429e+06 0.034215 Completed
24 ts_wavenet_gru_^GSPC No 12 2000000.0 2.207892e+06 0.103946 Completed
25 ts_wavenet_lstm_^GSPC No 13 2000000.0 2.363158e+06 0.181579 Completed
26 ts_gru_2_^GSPC No 16 2000000.0 2.001147e+06 0.000574 Completed
27 all_All_^GSPC No 15 2000000.0 1.993714e+06 -0.003143 Completed
46 ts_gru_1_sl_tsl_ai_tr_1_^GSPC No 206 2000000.0 2.739502e+06 0.369751 Completed
47 ts_lstm_sl_tsl_ai_tr_1_^GSPC No 208 2000000.0 2.551945e+06 0.275973 Completed
48 ts_conv1d_gru_sl_tsl_ai_tr_1_^GSPC No 204 2000000.0 3.060233e+06 0.530116 Completed
49 ts_conv1d_lstm_sl_tsl_ai_tr_1_^GSPC No 204 2000000.0 2.682023e+06 0.341012 Completed
50 ts_wavenet_sl_tsl_ai_tr_1_^GSPC No 201 2000000.0 2.691058e+06 0.345529 Completed
51 ts_wavenet_gru_sl_tsl_ai_tr_1_^GSPC No 199 2000000.0 2.762915e+06 0.381458 Completed
52 ts_wavenet_lstm_sl_tsl_ai_tr_1_^GSPC No 197 2000000.0 2.932721e+06 0.466360 Completed
53 ts_gru_2_sl_tsl_ai_tr_1_^GSPC No 206 2000000.0 2.739502e+06 0.369751 Completed
54 all_All_sl_tsl_ai_tr_1_^GSPC No 171 2000000.0 2.561543e+06 0.280772 Completed
73 ts_gru_1_sl_tsl_ai_tr_2_^GSPC No 221 2000000.0 3.776958e+06 0.888479 Completed
74 ts_lstm_sl_tsl_ai_tr_2_^GSPC No 224 2000000.0 3.515695e+06 0.757848 Completed
75 ts_conv1d_gru_sl_tsl_ai_tr_2_^GSPC No 223 2000000.0 3.806870e+06 0.903435 Completed
76 ts_conv1d_lstm_sl_tsl_ai_tr_2_^GSPC No 219 2000000.0 3.385762e+06 0.692881 Completed
77 ts_wavenet_sl_tsl_ai_tr_2_^GSPC No 216 2000000.0 3.405533e+06 0.702766 Completed
78 ts_wavenet_gru_sl_tsl_ai_tr_2_^GSPC No 214 2000000.0 3.535953e+06 0.767977 Completed
79 ts_wavenet_lstm_sl_tsl_ai_tr_2_^GSPC No 213 2000000.0 3.594707e+06 0.797353 Completed
80 ts_gru_2_sl_tsl_ai_tr_2_^GSPC No 221 2000000.0 3.776958e+06 0.888479 Completed
81 all_All_sl_tsl_ai_tr_2_^GSPC No 183 2000000.0 3.182832e+06 0.591416 Completed
100 ts_gru_1_sl_tsl_ai_tr_3_^GSPC No 179 2000000.0 2.404060e+06 0.202030 Completed
101 ts_lstm_sl_tsl_ai_tr_3_^GSPC No 181 2000000.0 2.483223e+06 0.241612 Completed
102 ts_conv1d_gru_sl_tsl_ai_tr_3_^GSPC No 177 2000000.0 3.376032e+06 0.688016 Completed
103 ts_conv1d_lstm_sl_tsl_ai_tr_3_^GSPC No 176 2000000.0 2.414231e+06 0.207115 Completed
104 ts_wavenet_sl_tsl_ai_tr_3_^GSPC No 167 2000000.0 2.866459e+06 0.433230 Completed
105 ts_wavenet_gru_sl_tsl_ai_tr_3_^GSPC No 170 2000000.0 2.958953e+06 0.479476 Completed
106 ts_wavenet_lstm_sl_tsl_ai_tr_3_^GSPC No 166 2000000.0 3.177859e+06 0.588929 Completed
107 ts_gru_2_sl_tsl_ai_tr_3_^GSPC No 179 2000000.0 2.404060e+06 0.202030 Completed
108 all_All_sl_tsl_ai_tr_3_^GSPC No 147 2000000.0 2.572683e+06 0.286341 Completed
127 ts_gru_1_sl_tsl_ai_tr_4_^GSPC No 221 2000000.0 3.944198e+06 0.972099 Completed
128 ts_lstm_sl_tsl_ai_tr_4_^GSPC No 225 2000000.0 3.653488e+06 0.826744 Completed
129 ts_conv1d_gru_sl_tsl_ai_tr_4_^GSPC No 223 2000000.0 3.970877e+06 0.985438 Completed
130 ts_conv1d_lstm_sl_tsl_ai_tr_4_^GSPC No 220 2000000.0 3.520191e+06 0.760096 Completed
131 ts_wavenet_sl_tsl_ai_tr_4_^GSPC No 216 2000000.0 3.530773e+06 0.765386 Completed
132 ts_wavenet_gru_sl_tsl_ai_tr_4_^GSPC No 214 2000000.0 3.685677e+06 0.842838 Completed
133 ts_wavenet_lstm_sl_tsl_ai_tr_4_^GSPC No 214 2000000.0 3.744163e+06 0.872081 Completed
134 ts_gru_2_sl_tsl_ai_tr_4_^GSPC No 221 2000000.0 3.944198e+06 0.972099 Completed
135 all_All_sl_tsl_ai_tr_4_^GSPC No 183 2000000.0 3.293279e+06 0.646639 Completed
154 ts_gru_1_sl_tsl_ai_tr_5_^GSPC No 219 2000000.0 3.447678e+06 0.723839 Completed
155 ts_lstm_sl_tsl_ai_tr_5_^GSPC No 222 2000000.0 3.144881e+06 0.572440 Completed
156 ts_conv1d_gru_sl_tsl_ai_tr_5_^GSPC No 218 2000000.0 3.676298e+06 0.838149 Completed
157 ts_conv1d_lstm_sl_tsl_ai_tr_5_^GSPC No 218 2000000.0 3.083448e+06 0.541724 Completed
158 ts_wavenet_sl_tsl_ai_tr_5_^GSPC No 212 2000000.0 3.244706e+06 0.622353 Completed
159 ts_wavenet_gru_sl_tsl_ai_tr_5_^GSPC No 208 2000000.0 3.390694e+06 0.695347 Completed
160 ts_wavenet_lstm_sl_tsl_ai_tr_5_^GSPC No 207 2000000.0 3.495297e+06 0.747649 Completed
161 ts_gru_2_sl_tsl_ai_tr_5_^GSPC No 219 2000000.0 3.447678e+06 0.723839 Completed
162 all_All_sl_tsl_ai_tr_5_^GSPC No 182 2000000.0 2.927901e+06 0.463950 Completed
165 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 2.393362e+06 0.196681 Completed
Trades Detail Metrics
In [200]:
tsExecuteEngine.getTradesTransactionDetailsDF().to_excel("portf_N_trades_transaction_details.xlsx")

WFA Backtest

A type of backtests that are designed to simulate fitting AI Models to different date ranges or to shift the date ranges for a backtest through time.

- Description :

- Re-fit the AI models that a given trade strategy depends on during a backtest

- Scenario:

- Given the following initial setting for a backtest:

    AI Models Fit Date Ranges
        1. Training Period: 
            1. Begin Date = 2001-01-01 
            2. End Date   = 2005-12-31  
        2. Validation Period: 
            1. Begin Date = 2006-01-01 
            2. End Date   = 2007-06-30   

    Test Period: 
        1. Begin Date = 2008-01-01 
        2. End Date   = 2008-12-31 

- Re-fit the models after the backtest has executed for a period (n days, n weeks, n months), by 
  either shifting the Training and Validation period or extending, that is anchoring the Training
  Period start date

Example 1

  • shifting Training and Validation periods
  • re-fit every three months
  • the AI Models will be trained and validate with the following date ranges:
    • Iteration 1:
      1. Training Period: 
          1. Begin Date = 2001-01-01 
          2. End Date   = 2005-12-31  
      2. Validation Period: 
          1. Begin Date = 2006-01-01 
          2. End Date   = 2007-06-30   
    • Iteration 2:
      1. Training Period: 
          1. Begin Date = 2001-04-01 
          2. End Date   = 2006-03-31  
      2. Validation Period: 
          1. Begin Date = 2006-04-01 
          2. End Date   = 2007-09-30    
      
      • Iteration n: ...
  • The backtest, for dates between 2008-04-01 and 2008-06-30, will use the updated re-fitted models
  • The re-fit process will continue throughout the backtest until the backtest ends.

Example 2

  • anchored Training Set
  • re-fit every three months
  • the AI Models will be trained and validate with the following date ranges:
    • Iteration 1:
      1. Training Period: 
          1. Begin Date = 2001-01-01 
          2. End Date   = 2005-12-31  
      2. Validation Period: 
          1. Begin Date = 2006-01-01 
          2. End Date   = 2007-06-30  
    • Iteration 2:
      1. Training Period: 
          1. Begin Date = 2001-01-01 
          2. End Date   = 2006-03-31  
      2. Validation Period: 
          1. Begin Date = 2006-04-01 
          2. End Date   = 2007-09-30 
    • Iteration n:
      ... 
  • The backtest, for dates between 2008-04-01 and 2008-06-30, will use the updated re-fitted models
  • The re-fit process will continue throughout the backtest

WFA-Backtest 1

Description:

  • Portfolio uses all trade strategies in Portfolio F
  • Re-fit AI trading models every 4 months. For this example, there will be a total of three times the AI models are fitted, that is:
    1. Before WFA Backtest starts
    2. May 1
    3. September 1
  • Training-set is not anchored

Backtest:

1. Type: WFA Backtest
2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2000-01-01 
        2. End Date   = 2005-12-31  
    2. Validation Period: 
        1. Begin Date = 2006-01-01 
        2. End Date   = 2007-12-31   
4. Test Period: 
    1. Begin Date = 2008-01-01 
    2. End Date   = 2008-12-31         

Portfolio Trade Assets

In [18]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [19]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        forceCreateMarketData  = False,                                      
        interval               = "1d"  ) 
In [20]:
MarketData.getDateRangesForStocks( ts_marketdat_mng.marketDataObj.getDataFrame() )
Out[20]:
Index Beg_Date End_Date
0 ^GSPC 1980-01-02 2021-12-08
1 ^IXIC 1980-01-02 2021-12-08
2 ^DJI 1992-01-02 2021-12-08
3 SPXL 2008-11-05 2021-12-08
4 SPXS 2008-11-19 2021-12-08
5 SDOW 2010-02-11 2021-12-08
6 SQQQ 2010-02-11 2021-12-08
7 TQQQ 2010-02-11 2021-12-08
8 UDOW 2010-02-11 2021-12-08

Simulation Broker

In [21]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [67]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [23]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "WFA-Backtest 1",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [24]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  15

Training, Validation and Test Periods for Backtest

In [25]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "1999-07-01",
                             strBegDate         = "2000-01-01",
                             strEndDate         = "2005-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2005-07-01",
                               strBegDate         = "2006-01-01",
                               strEndDate         = "2007-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2007-07-01",
                               strBegDate         = "2008-01-01",
                               strEndDate         = "2008-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute WFA Backtest

In [26]:
tsExecuteEngine = BacktestExecutionWFA( \
            name                        = "WFA-Backtest 1",
            test_period                 = testing_period,
            fit_datasets_start          = fit_datasets,
            trade_asset_registered_item = portf_registered_obj,
            wfa_slide_win_size          = 4,
            wfa_slide_win_period        = WFASlideWindowPeriod.Months, 
            anchor_fit_dataset          = False )                      
In [27]:
tsExecuteEngine.evaluate()
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************

**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************

**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  LSTM_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

Backtest Metrics

Save to Excel
In [31]:
tsExecuteEngine.getSummaryMetrics().to_excel("WFA-Backtest-1 backtest-metrics.xlsx")
Out[31]:
ta_reg_item_name ta_reg_item_id is_portfolio trade_asset model_type order_type trade_on_etf enter_model_unique_name enter_ensemble_model enter_num_models ... Avg. Drawdown Avg. Drawdown Days Recovery Factor Ulcer Index Avg. Up Month Avg. Down Month Win Days % Win Month % Win Quarter % Win Year %
0 WFA-Backtest 1 None Yes 0 ... -0.04 16 2.77 19.23 0.04 -0.05 0.52 0.92 1.0 1.0
1 ts_lstm_1_^DJI None No ^DJI Static Market False ts_lstm_1 No 1 ... -0.04 9 6.87 1.02 0.1 -0.05 0.54 0.92 1.0 1.0
2 ts_lstm_3_^DJI None No ^DJI Static Market False ts_lstm_3 No 1 ... -0.04 9 6.87 1.02 0.1 -0.05 0.54 0.92 1.0 1.0
3 ts_lstm_5_^DJI None No ^DJI Static Market False ts_lstm_5 No 1 ... -0.04 9 6.87 1.02 0.1 -0.05 0.54 0.92 1.0 1.0
4 all_All_^DJI None No ^DJI Static Market False ensemble Yes 3 ... -0.04 9 6.87 1.02 0.1 -0.05 0.54 0.92 1.0 1.0
5 ts_lstm_1_^IXIC None No ^IXIC Static Market False ts_lstm_1 No 1 ... -0.08 30 0.55 1.52 0.04 -0.04 0.5 0.67 0.75 1.0
6 ts_lstm_3_^IXIC None No ^IXIC Static Market False ts_lstm_3 No 1 ... -0.08 30 0.55 1.52 0.04 -0.04 0.5 0.67 0.75 1.0
7 ts_lstm_5_^IXIC None No ^IXIC Static Market False ts_lstm_5 No 1 ... -0.08 30 0.55 1.52 0.04 -0.04 0.5 0.67 0.75 1.0
8 all_All_^IXIC None No ^IXIC Static Market False ensemble Yes 3 ... -0.08 30 0.55 1.52 0.04 -0.04 0.5 0.67 0.75 1.0
9 ts_lstm_1_^GSPC None No ^GSPC Static Market False ts_lstm_1 No 1 ... -0.05 18 3.74 inf 0.16 -0.02 0.53 0.33 0.75 1.0
10 ts_lstm_3_^GSPC None No ^GSPC Static Market False ts_lstm_3 No 1 ... -0.05 18 3.74 inf 0.16 -0.02 0.53 0.33 0.75 1.0
11 ts_lstm_5_^GSPC None No ^GSPC Static Market False ts_lstm_5 No 1 ... -0.05 18 3.74 inf 0.16 -0.02 0.53 0.33 0.75 1.0
12 all_All_^GSPC None No ^GSPC Static Market False ensemble Yes 3 ... -0.05 18 3.74 inf 0.16 -0.02 0.53 0.33 0.75 1.0
13 Long-Only Trade Strategy for ^IXIC None No ^IXIC Static Market False None None None ... -0.49 362 -0.8 1.56 0.03 -0.1 0.46 0.5 0.25 0.0
14 Long-Only Trade Strategy for ^DJI None No ^DJI Static Market False None None None ... -0.26 180 -0.78 1.86 0.02 -0.05 0.48 0.25 0.0 0.0
15 Long-Only Trade Strategy for ^GSPC None No ^GSPC Static Market False None None None ... -0.48 362 -0.78 inf 0.02 -0.06 0.5 0.33 0.0 0.0

16 rows × 85 columns

Execution & Investment Metrics
In [29]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']]
Out[29]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
0 WFA-Backtest 1 Yes 455 30000000.0 4.541617e+07 0.513872 Completed
1 ts_lstm_1_^DJI No 51 2000000.0 5.034280e+06 1.517140 Completed
2 ts_lstm_3_^DJI No 51 2000000.0 5.034280e+06 1.517140 Completed
3 ts_lstm_5_^DJI No 51 2000000.0 5.034280e+06 1.517140 Completed
4 all_All_^DJI No 51 2000000.0 5.034280e+06 1.517140 Completed
5 ts_lstm_1_^IXIC No 36 2000000.0 2.253939e+06 0.126969 Completed
6 ts_lstm_3_^IXIC No 36 2000000.0 2.253939e+06 0.126969 Completed
7 ts_lstm_5_^IXIC No 36 2000000.0 2.253939e+06 0.126969 Completed
8 all_All_^IXIC No 36 2000000.0 2.253939e+06 0.126969 Completed
9 ts_lstm_1_^GSPC No 26 2000000.0 3.114723e+06 0.557361 Completed
10 ts_lstm_3_^GSPC No 26 2000000.0 3.114723e+06 0.557361 Completed
11 ts_lstm_5_^GSPC No 26 2000000.0 3.114723e+06 0.557361 Completed
12 all_All_^GSPC No 26 2000000.0 3.114723e+06 0.557361 Completed
13 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 1.209029e+06 -0.395486 Completed
14 Long-Only Trade Strategy for ^DJI No 1 2000000.0 1.347062e+06 -0.326469 Completed
15 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 1.248316e+06 -0.375842 Completed
Performance Metrics
In [30]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ]
Out[30]:
ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type exit_num_models exit_model exit_model_type stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
0 WFA-Backtest 1 Yes 0 0 2008-01-03 2008-12-31 0.51 0.52 1.55 -0.19 0.11 -0.07
1 ts_lstm_1_^DJI No ^DJI Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 1.52 1.53 2.63 -0.22 0.11 -0.07
2 ts_lstm_3_^DJI No ^DJI Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 1.52 1.53 2.63 -0.22 0.11 -0.07
3 ts_lstm_5_^DJI No ^DJI Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 1.52 1.53 2.63 -0.22 0.11 -0.07
4 all_All_^DJI No ^DJI Market 3 composite 3 composite 2008-01-03 2008-12-31 1.52 1.53 2.63 -0.22 0.11 -0.07
5 ts_lstm_1_^IXIC No ^IXIC Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 0.13 0.13 0.5 -0.23 0.12 -0.08
6 ts_lstm_3_^IXIC No ^IXIC Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 0.13 0.13 0.5 -0.23 0.12 -0.08
7 ts_lstm_5_^IXIC No ^IXIC Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 0.13 0.13 0.5 -0.23 0.12 -0.08
8 all_All_^IXIC No ^IXIC Market 3 composite 3 composite 2008-01-03 2008-12-31 0.13 0.13 0.5 -0.23 0.12 -0.08
9 ts_lstm_1_^GSPC No ^GSPC Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 0.56 0.56 1.3 -0.15 0.12 -0.09
10 ts_lstm_3_^GSPC No ^GSPC Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 0.56 0.56 1.3 -0.15 0.12 -0.09
11 ts_lstm_5_^GSPC No ^GSPC Market 1 lstm AI 1 lstm AI 2008-01-03 2008-12-31 0.56 0.56 1.3 -0.15 0.12 -0.09
12 all_All_^GSPC No ^GSPC Market 3 composite 3 composite 2008-01-03 2008-12-31 0.56 0.56 1.3 -0.15 0.12 -0.09
13 Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None None None None 2008-01-03 2008-12-31 -0.4 -0.4 -1.02 -0.49 0.12 -0.09
14 Long-Only Trade Strategy for ^DJI No ^DJI Market None None None None None None 2008-01-03 2008-12-31 -0.33 -0.33 -0.86 -0.42 0.11 -0.08
15 Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None None None None 2008-01-03 2008-12-31 -0.38 -0.38 -0.94 -0.48 0.12 -0.09

WFA-Backtest 2

Description:

  • Portfolio has a subset of the trade strategies in Portfolio G
    • Smaller subset of TA and AI models to reduce execution duration
  • Re-fit AI trading models every 6 months
  • Training-set is anchored

Backtest:

1. Type: WFA Backtest
2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2000-01-01 
        2. End Date   = 2005-12-31  
    2. Validation Period: 
        1. Begin Date = 2006-01-01 
        2. End Date   = 2007-12-31   
4. Test Period: 
    1. Begin Date = 2008-01-01 
    2. End Date   = 2010-12-31  

Portfolio Trade Assets

In [32]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [33]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 

Simulation Broker

In [34]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [35]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },

                               "stop_lost" :
                                    { 'model'    : "fix_perc",
                                      'type'     : "ta",
                                      'obj_args' : { 'long_stop_los_per' : 5, 'short_stop_los_per'    : 5 }  } 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 30,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )

# TS #16

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #17

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [36]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "WFA-Backtest 2",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [37]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  27

Training, Validation and Test Periods for Backtest

In [39]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "1999-07-01",
                             strBegDate         = "2000-01-01",
                             strEndDate         = "2005-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2005-07-01",
                               strBegDate         = "2006-01-01",
                               strEndDate         = "2007-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2007-07-01",
                               strBegDate         = "2008-01-01",
                               strEndDate         = "2010-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute WFA Backtest

In [40]:
tsExecuteEngine = BacktestExecutionWFA( \
            name                        = "WFA-Backtest 2",
            test_period                 = testing_period,
            fit_datasets_start          = fit_datasets,
            trade_asset_registered_item = portf_registered_obj,
            wfa_slide_win_size          = 6,
            wfa_slide_win_period        = WFASlideWindowPeriod.Months, 
            anchor_fit_dataset          = True )                      
In [41]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-02-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-05 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-17 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-07 00:00:00 
****************

Backtest Metrics

Save to Excel
In [42]:
tsExecuteEngine.getSummaryMetrics().to_excel("WFA-Backtest-2 backtest-metrics.xlsx")
Trade Strategies Execution & Investment Metrics

DOW Jones

In [43]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[43]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_gru_1_^DJI No 179 2000000.0 5.095588e+06 1.547794 Completed
2 ts_lstm_^DJI No 169 2000000.0 6.891720e+06 2.445860 Completed
3 ts_conv1d_gru_^DJI No 132 2000000.0 6.775810e+06 2.387905 Completed
4 ts_gru_2_^DJI No 179 2000000.0 5.095588e+06 1.547794 Completed
5 ts_sma_2_^DJI No 12 2000000.0 2.667955e+06 0.333977 Completed
6 ts_kama_^DJI No 9 2000000.0 2.880254e+06 0.440127 Completed
7 ts_tsi_^DJI No 33 2000000.0 2.538708e+06 0.269354 Completed
8 all_All_^DJI No 146 2000000.0 5.182988e+06 1.591494 Completed
26 Long-Only Trade Strategy for ^DJI No 1 2000000.0 1.775633e+06 -0.112183 Completed

Nasdaq

In [44]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[44]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
9 ts_gru_1_^IXIC No 50 2000000.0 1.234317e+06 -0.382841 Completed
10 ts_lstm_^IXIC No 132 2000000.0 2.258218e+06 0.129109 Completed
11 ts_conv1d_gru_^IXIC No 75 2000000.0 1.286739e+06 -0.356631 Completed
12 ts_gru_2_^IXIC No 50 2000000.0 1.234317e+06 -0.382841 Completed
13 ts_sma_2_^IXIC No 16 2000000.0 2.613678e+06 0.306839 Completed
14 ts_kama_^IXIC No 12 2000000.0 3.150188e+06 0.575094 Completed
15 ts_tsi_^IXIC No 30 2000000.0 2.646350e+06 0.323175 Completed
16 all_All_^IXIC No 98 2000000.0 1.322616e+06 -0.338692 Completed
25 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.033122e+06 0.016561 Completed

S&P 500

In [45]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[45]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
17 ts_gru_1_^GSPC No 92 2000000.0 2.890509e+06 0.445255 Completed
18 ts_lstm_^GSPC No 110 2000000.0 4.529307e+06 1.264654 Completed
19 ts_conv1d_gru_^GSPC No 120 2000000.0 2.586149e+06 0.293074 Completed
20 ts_gru_2_^GSPC No 92 2000000.0 2.890509e+06 0.445255 Completed
21 ts_sma_2_^GSPC No 15 2000000.0 2.936310e+06 0.468155 Completed
22 ts_kama_^GSPC No 5 2000000.0 3.502907e+06 0.751454 Completed
23 ts_tsi_^GSPC No 37 2000000.0 2.233807e+06 0.116904 Completed
24 all_All_^GSPC No 94 2000000.0 3.066362e+06 0.533181 Completed
27 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 1.738083e+06 -0.130958 Completed
Performance Metrics

Dow Jones

In [46]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')
Out[46]:
ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type exit_num_models exit_model exit_model_type stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 ts_gru_1_^DJI No ^DJI Market 1 gru AI 1 gru AI 2008-01-03 2010-12-31 1.55 0.37 1.26 -0.24 0.11 -0.07
2 ts_lstm_^DJI No ^DJI Market 1 lstm AI 1 lstm AI 2008-01-03 2010-12-31 2.45 0.51 1.63 -0.22 0.11 -0.07
3 ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI 1 conv1d_gru AI 2008-01-03 2010-12-31 2.39 0.5 1.61 -0.24 0.11 -0.08
4 ts_gru_2_^DJI No ^DJI Market 1 gru AI 1 gru AI 2008-01-03 2010-12-31 1.55 0.37 1.26 -0.24 0.11 -0.07
5 ts_sma_2_^DJI No ^DJI Market 1 sma TA 1 sma TA 2008-01-03 2010-12-31 0.33 0.1 0.58 -0.2 0.06 -0.06
6 ts_kama_^DJI No ^DJI Market 1 kama TA 1 kama TA 2008-01-03 2010-12-31 0.44 0.13 0.74 -0.27 0.05 -0.05
7 ts_tsi_^DJI No ^DJI Market 1 tsi TA 1 tsi TA 2008-01-03 2010-12-31 0.27 0.08 0.46 -0.25 0.07 -0.07
8 all_All_^DJI No ^DJI Market 7 composite 7 composite 2008-01-03 2010-12-31 1.59 0.37 1.29 -0.22 0.11 -0.07
26 Long-Only Trade Strategy for ^DJI No ^DJI Market None None None None None None 2008-01-03 2010-12-31 -0.11 -0.04 -0.01 -0.5 0.11 -0.08

Nasdaq

In [47]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')
Out[47]:
ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type exit_num_models exit_model exit_model_type stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
9 ts_gru_1_^IXIC No ^IXIC Market 1 gru AI 1 gru AI 2008-01-03 2010-12-31 -0.38 -0.15 -0.34 -0.59 0.12 -0.07
10 ts_lstm_^IXIC No ^IXIC Market 1 lstm AI 1 lstm AI 2008-01-03 2010-12-31 0.13 0.04 0.29 -0.3 0.12 -0.08
11 ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI 1 conv1d_gru AI 2008-01-03 2010-12-31 -0.36 -0.14 -0.3 -0.47 0.11 -0.11
12 ts_gru_2_^IXIC No ^IXIC Market 1 gru AI 1 gru AI 2008-01-03 2010-12-31 -0.38 -0.15 -0.34 -0.59 0.12 -0.07
13 ts_sma_2_^IXIC No ^IXIC Market 1 sma TA 1 sma TA 2008-01-03 2010-12-31 0.31 0.09 0.47 -0.31 0.09 -0.07
14 ts_kama_^IXIC No ^IXIC Market 1 kama TA 1 kama TA 2008-01-03 2010-12-31 0.57 0.16 0.77 -0.23 0.08 -0.07
15 ts_tsi_^IXIC No ^IXIC Market 1 tsi TA 1 tsi TA 2008-01-03 2010-12-31 0.32 0.1 0.5 -0.31 0.08 -0.07
16 all_All_^IXIC No ^IXIC Market 7 composite 7 composite 2008-01-03 2010-12-31 -0.34 -0.13 -0.29 -0.51 0.11 -0.11
25 Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None None None None 2008-01-03 2010-12-31 0.02 0.01 0.17 -0.51 0.12 -0.09

S&P 500

In [48]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')
Out[48]:
ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type exit_num_models exit_model exit_model_type stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
17 ts_gru_1_^GSPC No ^GSPC Market 1 gru AI 1 gru AI 2008-01-03 2010-12-31 0.45 0.13 0.54 -0.49 0.12 -0.08
18 ts_lstm_^GSPC No ^GSPC Market 1 lstm AI 1 lstm AI 2008-01-03 2010-12-31 1.27 0.31 1.05 -0.32 0.12 -0.08
19 ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI 1 conv1d_gru AI 2008-01-03 2010-12-31 0.29 0.09 0.44 -0.42 0.12 -0.09
20 ts_gru_2_^GSPC No ^GSPC Market 1 gru AI 1 gru AI 2008-01-03 2010-12-31 0.45 0.13 0.54 -0.49 0.12 -0.08
21 ts_sma_2_^GSPC No ^GSPC Market 1 sma TA 1 sma TA 2008-01-03 2010-12-31 0.47 0.14 0.67 -0.26 0.07 -0.06
22 ts_kama_^GSPC No ^GSPC Market 1 kama TA 1 kama TA 2008-01-03 2010-12-31 0.75 0.21 1.03 -0.15 0.06 -0.05
23 ts_tsi_^GSPC No ^GSPC Market 1 tsi TA 1 tsi TA 2008-01-03 2010-12-31 0.12 0.04 0.27 -0.27 0.09 -0.07
24 all_All_^GSPC No ^GSPC Market 7 composite 7 composite 2008-01-03 2010-12-31 0.53 0.15 0.64 -0.44 0.12 -0.09
27 Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None None None None 2008-01-03 2010-12-31 -0.13 -0.05 -0.0 -0.53 0.12 -0.09

WFA-Backtest 3

Description:

  • Same trade strategies as Portfolio G
  • Re-fit AI trading models every 6 months
  • Training-set is not anchored

Backtest:

1. Type: WFA Backtest
2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2003-01-01 
        2. End Date   = 2008-12-31  
    2. Validation Period: 
        1. Begin Date = 2009-01-01 
        2. End Date   = 2010-12-31   
4. Test Period: 
    1. Begin Date = 2011-01-01 
    2. End Date   = 2012-12-31  

Portfolio Trade Assets

In [49]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [50]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 

Simulation Broker

In [51]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [53]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },

                               "stop_lost" :
                                    { 'model'    : "fix_perc",
                                      'type'     : "ta",
                                      'obj_args' : { 'long_stop_los_per' : 5, 'short_stop_los_per'    : 5 }  } 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

# TS #9

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #11

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_bb",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "bb",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 13, 'window_dev' : 1 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #12

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_macd",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 26, 'window_fast' : 12, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #13

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_rsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "rsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'rsi_enter_long'  : 30.0,  'rsi_exit_long'  : 30.0, 
                                                 'rsi_enter_short' : 70.0,  'rsi_exit_short' : 70.0 },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #14

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_srsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "srsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 14,  'smooth1' : 3, 'smooth2'  : 3,
                                                 'srsi_enter_long'  : 0.8,  'srsi_exit_long'  : 0.8,
                                                 'srsi_enter_short' : 0.2,  'srsi_exit_short' : 0.2 },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #15

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_adx",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "adx",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'adx_enter_long_ge' : 14, 'adx_exit_long_lt'  : 14,
                                             'adx_enter_short_ge' : 14, 'adx_exit_short_lt' : 14 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #16

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #17

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #18

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_forceindex",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "forceindex",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 39 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #19

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_mfi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "mfi",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'long_slope_win' : 15, 'short_slope_win' : 15 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [54]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "WFA-Backtest 3",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [55]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  63

Training, Validation and Test Periods for Backtest

In [56]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2002-07-01",
                             strBegDate         = "2003-01-01",
                             strEndDate         = "2008-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2008-07-01",
                               strBegDate         = "2009-01-01",
                               strEndDate         = "2010-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2010-07-01",
                               strBegDate         = "2011-01-01",
                               strEndDate         = "2012-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute WFA Backtest

In [57]:
tsExecuteEngine = BacktestExecutionWFA( \
            name                        = "WFA-Backtest 3",
            test_period                 = testing_period,
            fit_datasets_start          = fit_datasets,
            trade_asset_registered_item = portf_registered_obj,
            wfa_slide_win_size          = 6,
            wfa_slide_win_period        = WFASlideWindowPeriod.Months, 
            anchor_fit_dataset          = False )                      
In [58]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-12-13 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-02-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-03-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-04-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-05-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-06-06 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-07-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-09-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-10-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-11-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-12-27 00:00:00 
****************

Backtest Metrics

Save to Excel
In [59]:
tsExecuteEngine.getSummaryMetrics().to_excel("WFA-Backtest-3 backtest-metrics.xlsx")
Trade Strategies Execution & Investment Metrics

DOW Jones

In [60]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[60]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_gru_1_^DJI No 98 2000000.0 1.704969e+06 -0.147515 Completed
2 ts_lstm_^DJI No 99 2000000.0 2.900777e+06 0.450389 Completed
3 ts_conv1d_gru_^DJI No 73 2000000.0 2.648166e+06 0.324083 Completed
4 ts_conv1d_lstm_^DJI No 83 2000000.0 3.027643e+06 0.513822 Completed
5 ts_wavenet_^DJI No 49 2000000.0 2.592893e+06 0.296446 Completed
6 ts_wavenet_gru_^DJI No 64 2000000.0 2.522466e+06 0.261233 Completed
7 ts_wavenet_lstm_^DJI No 72 2000000.0 2.370577e+06 0.185288 Completed
8 ts_gru_2_^DJI No 98 2000000.0 1.704969e+06 -0.147515 Completed
9 ts_sma_1_^DJI No 13 2000000.0 1.761023e+06 -0.119488 Completed
10 ts_sma_2_^DJI No 11 2000000.0 1.840185e+06 -0.079907 Completed
11 ts_bb_^DJI No 83 2000000.0 2.003423e+06 0.001712 Completed
12 ts_macd_^DJI No 41 2000000.0 1.860459e+06 -0.069770 Completed
13 ts_rsi_^DJI No 18 2000000.0 2.066401e+06 0.033201 Completed
14 ts_srsi_^DJI No 81 2000000.0 1.932650e+06 -0.033675 Completed
15 ts_adx_^DJI No 50 2000000.0 1.460910e+06 -0.269545 Completed
16 ts_kama_^DJI No 8 2000000.0 1.987372e+06 -0.006314 Completed
17 ts_tsi_^DJI No 26 2000000.0 1.757024e+06 -0.121488 Completed
18 ts_forceindex_^DJI No 25 2000000.0 1.927163e+06 -0.036419 Completed
19 ts_mfi_^DJI No 78 2000000.0 1.789909e+06 -0.105045 Completed
20 all_All_^DJI No 125 2000000.0 2.216613e+06 0.108306 Completed
62 Long-Only Trade Strategy for ^DJI No 1 2000000.0 2.245110e+06 0.122555 Completed

Nasdaq

In [61]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[61]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
21 ts_gru_1_^IXIC No 118 2000000.0 2.579363e+06 0.289682 Completed
22 ts_lstm_^IXIC No 75 2000000.0 2.722656e+06 0.361328 Completed
23 ts_conv1d_gru_^IXIC No 35 2000000.0 2.452429e+06 0.226214 Completed
24 ts_conv1d_lstm_^IXIC No 53 2000000.0 2.551031e+06 0.275515 Completed
25 ts_wavenet_^IXIC No 43 2000000.0 1.844244e+06 -0.077878 Completed
26 ts_wavenet_gru_^IXIC No 45 2000000.0 3.345826e+06 0.672913 Completed
27 ts_wavenet_lstm_^IXIC No 55 2000000.0 2.697010e+06 0.348505 Completed
28 ts_gru_2_^IXIC No 118 2000000.0 2.579363e+06 0.289682 Completed
29 ts_sma_1_^IXIC No 15 2000000.0 1.482456e+06 -0.258772 Completed
30 ts_sma_2_^IXIC No 16 2000000.0 1.613525e+06 -0.193238 Completed
31 ts_bb_^IXIC No 90 2000000.0 2.399141e+06 0.199571 Completed
32 ts_macd_^IXIC No 55 2000000.0 2.001787e+06 0.000894 Completed
33 ts_rsi_^IXIC No 23 2000000.0 2.140877e+06 0.070438 Completed
34 ts_srsi_^IXIC No 79 2000000.0 1.625483e+06 -0.187258 Completed
35 ts_adx_^IXIC No 39 2000000.0 1.477245e+06 -0.261377 Completed
36 ts_kama_^IXIC No 11 2000000.0 1.479783e+06 -0.260108 Completed
37 ts_tsi_^IXIC No 25 2000000.0 1.820010e+06 -0.089995 Completed
38 ts_forceindex_^IXIC No 42 2000000.0 1.538729e+06 -0.230635 Completed
39 ts_mfi_^IXIC No 75 2000000.0 2.296757e+06 0.148379 Completed
40 all_All_^IXIC No 148 2000000.0 2.412305e+06 0.206153 Completed
61 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.243697e+06 0.121848 Completed

S&P 500

In [62]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[62]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
41 ts_gru_1_^GSPC No 97 2000000.0 2.270627e+06 0.135313 Completed
42 ts_lstm_^GSPC No 79 2000000.0 2.299793e+06 0.149897 Completed
43 ts_conv1d_gru_^GSPC No 72 2000000.0 2.530711e+06 0.265356 Completed
44 ts_conv1d_lstm_^GSPC No 95 2000000.0 2.635817e+06 0.317908 Completed
45 ts_wavenet_^GSPC No 54 2000000.0 2.477118e+06 0.238559 Completed
46 ts_wavenet_gru_^GSPC No 50 2000000.0 2.390409e+06 0.195204 Completed
47 ts_wavenet_lstm_^GSPC No 91 2000000.0 2.364480e+06 0.182240 Completed
48 ts_gru_2_^GSPC No 97 2000000.0 2.270627e+06 0.135313 Completed
49 ts_sma_1_^GSPC No 17 2000000.0 1.736157e+06 -0.131922 Completed
50 ts_sma_2_^GSPC No 12 2000000.0 1.939863e+06 -0.030068 Completed
51 ts_bb_^GSPC No 102 2000000.0 2.416640e+06 0.208320 Completed
52 ts_macd_^GSPC No 63 2000000.0 1.597846e+06 -0.201077 Completed
53 ts_rsi_^GSPC No 24 2000000.0 2.020677e+06 0.010338 Completed
54 ts_srsi_^GSPC No 80 2000000.0 1.817898e+06 -0.091051 Completed
55 ts_adx_^GSPC No 49 2000000.0 1.578123e+06 -0.210939 Completed
56 ts_kama_^GSPC No 8 2000000.0 1.807966e+06 -0.096017 Completed
57 ts_tsi_^GSPC No 27 2000000.0 1.659028e+06 -0.170486 Completed
58 ts_forceindex_^GSPC No 39 2000000.0 1.370218e+06 -0.314891 Completed
59 ts_mfi_^GSPC No 71 2000000.0 1.478256e+06 -0.260872 Completed
60 all_All_^GSPC No 165 2000000.0 1.857202e+06 -0.071399 Completed
63 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 2.242591e+06 0.121295 Completed
Performance Metrics

Dow Jones

In [ ]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')

Nasdaq

In [ ]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')

S&P 500

In [ ]:
tsExecuteEngine.getSummaryMetrics()\
[ ['ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')

Persist Backtest to DB (optional )

In [ ]:
session.add( tsExecuteEngine )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst)
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")

Slide Window WFA Backtest

- Description :

- Run a set of backtests by shifting the Training, Validation and Test Periods through time, or
  increasing the duration of the Training and Validation Periods through time and shifting only
  the Test Period
- Purpose of these set of backtest is to analysis the out-of-sample performance for trade strategies
  and/or portfolios through time
- The sliding-window of the training, validation, and test periods are configurable.
- This type of backtest is combined with the regular WFA backtest, which allows to re-fit
  models during each sliding window shift per the configuration of the regular WFA Backtest. 
- This type of backtest can be thought of as double sliding window, one sliding window for shifting or 
  increasing the size of the training and validation periods, the second one to control how often
  to re-fit models during a backtest.
- Due to the potential large number of backtests that can be executed, only the metadata, and summary 
  statistics and performance data are stored per backtest. 
      - All backtest statistical and metadata summary information is stored in a dataframe
      - The metadata information stored includes actual Fit Data Ranges, Test Period, and re-fit
        frequency during a backtest

- Example A:

- Scenario 1:
    - Fix Fit and Test Periods.

- Given the following initial setting for a backtest:

    Fit Dataset:   
        train:       1/1/2000 to 12/31/2004
        validation:  1/1/2005 to 12/31/2005

    Test Period:     1/1/2006 to 12/31/2006

- Run WFA backtests with the datasets above for different re-fit set frequencies, non-anchored:
    - 2 weeks
    - 1 month
    - 3 month

- This example will run the WFA defined part 1, three-times, re-fitting the AI models each time
  per the frequency defined.

- Example B:

- Scenario 2:
    - WFA Scenario implementation that slides through time the Fit datasets as well as the test period.

- Given the following initial setting for a backtest:

    Fit Dataset:   
        train:       1/1/2000 to 12/31/2004
        validation:  1/1/2005 to 12/31/2005

    Test Period:     1/1/2006 to 12/31/2006

- Run WFA backtests from the starting datasets above, incrementing sliding window of the datasets 
  for the Fit and Test periods by one-year, while the end date for the test period is less than 
  or equal to 12/31/2020

- Re-fit the AI Models in a backtest every 6 months, don't anchor the training set

- Each Iteration is one complete backtest, and in each backtest the AI Models are fitted at
  the start and at July 1 of the current backtest year.

    Iteration 1:
                    train:       1/1/2000 to 12/31/2004
                    validation:  1/1/2005 to 12/31/2005
                    Test Period: 1/1/2006 to 12/31/2006
    Iteration 2:
                    train:       1/1/2001 to 12/31/2005
                    validation:  1/1/2006 to 12/31/2006
                    Test Period: 1/1/2007 to 12/31/2007   
    ..
    ..
    Iteration Last:
        train:       1/1/2014 to 12/31/2018
        validation:  1/1/2019 to 12/31/2019
        Test Period: 1/1/2020 to 12/31/2020               

- Example C:

- Scenario 3:
    - WFA Scenario implementation that increases through time the date range of the Fit datasets, 
      but not the test period, as the fit dataset is anchored to its initial position. 
    - The train set is anchored, and the train and validation set are expanded in every iteration, 
      pushing the test period dataset forward in time, but with the same length. 
    - The increased per iteration of the train and validation set are configurable, as well as 
      the maximum end date for the test period.

- Given the following initial setting for a backtest:

    Fit Dataset:   
        train:       1/1/2000 to 12/31/2004
        validation:  1/1/2005 to 12/31/2005

    Test Period:     1/1/2006 to 12/31/2006

- Run WFA backtests from the starting datasets above, incrementing sliding window of the datasets 
  for the Fit and Test periods by one-year, while the end date for the test period is less than 
  or equal to 12/31/2020

- Re-fit the AI Models in a backtest every 6 months, don't anchor the training set

- This class will iterate through time by creating updated Fit datsets, and Test Periods, with 
  one year increments overall to the train and validation period. Train dataset increased by 9 months 
  per iteration, and Validation dataset by 3 months, the test period is just shifted by the one-year.
- that is:
    * Iteration 1:
                    train:       1/1/2000 to 12/31/2004
                    validation:  1/1/2005 to 12/31/2005
                    Test Period: 1/1/2006 to 12/31/2006
    * Iteration 2:
                    train:        1/1/2000  to  9/30/2005    (date range increased by nine-months)
                    validation:  10/1/2005  to 12/31/2006    (date range increaed by three-months and 
                                                              shifted by nine-months)
                    Test Period:  1/1/2007  to 12/31/2007    (date range shifted by one-year)
    * Iteration 3:
                    train:        1/1/2000  to  6/30/2006    (date range increased by nine-months)
                    validation:   7/1/2006  to 12/31/2007    (date range increaed by three-months and 
                                                              shifted by nine-months)
                    Test Period:  1/1/2008  to 12/31/2008    (date range shifted by one-year)
    ..
    ..

    * Iteration Last:
        train:       1/1/2000 to xxx
        validation:  yyy      to 12/31/2019       
        Test Period: 1/1/2020 to 12/31/2020                        

SW-WFA-Backtest 1

Description:

  • Same trade strategies as Portfolio F
  • Re-fit AI trading models every 3 months, then every 6 months within a backtest
  • Fixed Training and Validation periods
  • Training-set is not anchored during a backtest
  • $200K/strategy

Backtest:

1. Type: Slide Window WFA Backtest

2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2000-01-01 
        2. End Date   = 2005-12-31  
    2. Validation Period: 
        1. Begin Date = 2006-01-01 
        2. End Date   = 2007-12-31 

3. Test Period: 
    1. Begin Date = 2008-01-01 
    2. End Date   = 2008-12-31          

Portfolio Trade Assets

In [7]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [8]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
In [9]:
MarketData.getDateRangesForStocks( ts_marketdat_mng.marketDataObj.getDataFrame() )
Out[9]:
Index Beg_Date End_Date
0 ^GSPC 1980-01-02 2021-12-08
1 ^IXIC 1980-01-02 2021-12-08
2 ^DJI 1992-01-02 2021-12-08
3 SPXL 2008-11-05 2021-12-08
4 SPXS 2008-11-19 2021-12-08
5 SDOW 2010-02-11 2021-12-08
6 SQQQ 2010-02-11 2021-12-08
7 TQQQ 2010-02-11 2021-12-08
8 UDOW 2010-02-11 2021-12-08

Simulation Broker

In [10]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [11]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [12]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "SW-WFA-Backtest 1",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [13]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  30

Training, Validation and Test Periods for Backtest

In [14]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "1999-07-01",
                             strBegDate         = "2000-01-01",
                             strEndDate         = "2005-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2005-07-01",
                               strBegDate         = "2006-01-01",
                               strEndDate         = "2007-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2007-07-01",
                               strBegDate         = "2008-01-01",
                               strEndDate         = "2008-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute Slide Window WFA Backtest

In [15]:
tsExecuteEngine = BacktestExecutionSlideWindowWFA( \
            name                        = "SW-WFA-Backtest 1",
            trade_asset_registered_item = portf_registered_obj,
            wfa_slide_win_size_list     = [ 3, 6] , # list of int, associated with wfa_slide_win_period_list                            
            wfa_slide_win_period_list   = [ WFASlideWindowPeriod.Months, WFASlideWindowPeriod.Months ],
            wfa_sw_scenario_obj         = WFASlideWinScenarioFixDatasets(fit_dataset = fit_datasets,
                                                                         test_period = testing_period ),
            anchor_fit_dataset          = False )  
        
In [16]:
tsExecuteEngine.evaluate()
*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 1 ,  WFA SW Name: SW-WFA-Backtest 1      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioFixDatasets             
***
        -- Test Period                              
              beg = 2008-01-01 00:00:00,  end = 2008-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2000-01-01 00:00:00, end = 2005-12-31 00:00:00     
              validation -- beg = 2006-01-01 00:00:00, end = 2007-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

before self.wfa_backtest_sum_df len  0
after self.wfa_backtest_sum_df len  31

*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 2 ,  WFA SW Name: SW-WFA-Backtest 1      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 6 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioFixDatasets             
***
        -- Test Period                              
              beg = 2008-01-01 00:00:00,  end = 2008-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2000-01-01 00:00:00, end = 2005-12-31 00:00:00     
              validation -- beg = 2006-01-01 00:00:00, end = 2007-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

before self.wfa_backtest_sum_df len  31
after self.wfa_backtest_sum_df len  62

Backtest Metrics

Save to Excel
In [17]:
tsExecuteEngine.getSummaryMetrics().to_excel("SW-WFA-Backtest-1 backtest-metrics.xlsx")
Execution & Investment Metrics
In [ ]:
tsExecuteEngine.getSummaryMetrics().info()
Performance Metrics
In [81]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')
Out[81]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 1 3 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2008-01-03 2008-12-31 1.72 1.73 2.84 -0.19 0.11 -0.07
2 1 3 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2008-01-03 2008-12-31 1.43 1.44 2.53 -0.22 0.11 -0.07
3 1 3 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 1.39 1.4 2.53 -0.19 0.11 -0.07
4 1 3 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 1.51 1.53 2.67 -0.19 0.11 -0.07
5 1 3 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2008-01-03 2008-12-31 0.77 0.78 1.7 -0.28 0.11 -0.08
6 1 3 Months ts_wavenet_gru_^DJI No ^DJI Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 1.21 1.22 2.32 -0.22 0.11 -0.07
7 1 3 Months ts_wavenet_lstm_^DJI No ^DJI Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 1.5 1.51 2.66 -0.17 0.11 -0.06
8 1 3 Months ts_gru_2_^DJI No ^DJI Market 1 gru AI ... 2008-01-03 2008-12-31 1.72 1.73 2.84 -0.19 0.11 -0.07
9 1 3 Months all_All_^DJI No ^DJI Market 8 composite ... 2008-01-03 2008-12-31 1.35 1.36 2.47 -0.19 0.11 -0.07
29 1 3 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2008-01-03 2008-12-31 -0.33 -0.33 -0.86 -0.42 0.11 -0.08
32 2 6 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2008-01-03 2008-12-31 1.6 1.61 2.72 -0.19 0.11 -0.07
33 2 6 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2008-01-03 2008-12-31 1.43 1.44 2.53 -0.22 0.11 -0.07
34 2 6 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 1.35 1.36 2.48 -0.19 0.11 -0.07
35 2 6 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 1.51 1.53 2.67 -0.19 0.11 -0.07
36 2 6 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2008-01-03 2008-12-31 1.18 1.19 2.26 -0.19 0.11 -0.07
37 2 6 Months ts_wavenet_gru_^DJI No ^DJI Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 1.2 1.21 2.31 -0.22 0.11 -0.07
38 2 6 Months ts_wavenet_lstm_^DJI No ^DJI Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 2.0 2.02 3.17 -0.16 0.11 -0.07
39 2 6 Months ts_gru_2_^DJI No ^DJI Market 1 gru AI ... 2008-01-03 2008-12-31 1.6 1.61 2.72 -0.19 0.11 -0.07
40 2 6 Months all_All_^DJI No ^DJI Market 8 composite ... 2008-01-03 2008-12-31 1.27 1.28 2.38 -0.19 0.11 -0.07
60 2 6 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2008-01-03 2008-12-31 -0.33 -0.33 -0.86 -0.42 0.11 -0.08

20 rows × 23 columns

In [82]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')
Out[82]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
10 1 3 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2008-01-03 2008-12-31 0.3 0.3 0.83 -0.22 0.15 -0.07
11 1 3 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2008-01-03 2008-12-31 0.29 0.29 0.83 -0.22 0.12 -0.08
12 1 3 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 0.51 0.51 1.22 -0.18 0.15 -0.07
13 1 3 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 0.1 0.1 0.44 -0.29 0.12 -0.09
14 1 3 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2008-01-03 2008-12-31 0.37 0.37 0.97 -0.3 0.12 -0.09
15 1 3 Months ts_wavenet_gru_^IXIC No ^IXIC Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 0.02 0.02 0.26 -0.36 0.12 -0.09
16 1 3 Months ts_wavenet_lstm_^IXIC No ^IXIC Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 0.15 0.16 0.55 -0.32 0.12 -0.09
17 1 3 Months ts_gru_2_^IXIC No ^IXIC Market 1 gru AI ... 2008-01-03 2008-12-31 0.3 0.3 0.83 -0.22 0.15 -0.07
18 1 3 Months all_All_^IXIC No ^IXIC Market 8 composite ... 2008-01-03 2008-12-31 0.47 0.47 1.17 -0.23 0.12 -0.07
28 1 3 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2008-01-03 2008-12-31 -0.4 -0.4 -1.02 -0.49 0.12 -0.09
41 2 6 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2008-01-03 2008-12-31 0.27 0.27 0.78 -0.21 0.12 -0.07
42 2 6 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2008-01-03 2008-12-31 0.4 0.41 1.04 -0.22 0.12 -0.08
43 2 6 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 0.04 0.04 0.29 -0.23 0.1 -0.11
44 2 6 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 0.03 0.03 0.29 -0.27 0.12 -0.09
45 2 6 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2008-01-03 2008-12-31 0.21 0.21 0.67 -0.37 0.12 -0.09
46 2 6 Months ts_wavenet_gru_^IXIC No ^IXIC Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 -0.07 -0.07 0.04 -0.36 0.12 -0.09
47 2 6 Months ts_wavenet_lstm_^IXIC No ^IXIC Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 0.05 0.05 0.33 -0.34 0.12 -0.09
48 2 6 Months ts_gru_2_^IXIC No ^IXIC Market 1 gru AI ... 2008-01-03 2008-12-31 0.27 0.27 0.78 -0.21 0.12 -0.07
49 2 6 Months all_All_^IXIC No ^IXIC Market 8 composite ... 2008-01-03 2008-12-31 0.35 0.35 0.95 -0.22 0.12 -0.07
59 2 6 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2008-01-03 2008-12-31 -0.4 -0.4 -1.02 -0.49 0.12 -0.09

20 rows × 23 columns

In [83]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')
Out[83]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
19 1 3 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2008-01-03 2008-12-31 0.9 0.91 1.76 -0.27 0.11 -0.11
20 1 3 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2008-01-03 2008-12-31 0.61 0.62 1.39 -0.17 0.12 -0.09
21 1 3 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 1.68 1.7 2.67 -0.19 0.12 -0.08
22 1 3 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 0.77 0.77 1.65 -0.2 0.12 -0.09
23 1 3 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2008-01-03 2008-12-31 0.1 0.1 0.44 -0.32 0.12 -0.09
24 1 3 Months ts_wavenet_gru_^GSPC No ^GSPC Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 0.26 0.26 0.76 -0.26 0.12 -0.09
25 1 3 Months ts_wavenet_lstm_^GSPC No ^GSPC Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 0.19 0.19 0.63 -0.35 0.12 -0.09
26 1 3 Months ts_gru_2_^GSPC No ^GSPC Market 1 gru AI ... 2008-01-03 2008-12-31 0.9 0.91 1.76 -0.27 0.11 -0.11
27 1 3 Months all_All_^GSPC No ^GSPC Market 8 composite ... 2008-01-03 2008-12-31 1.62 1.63 2.59 -0.19 0.12 -0.08
30 1 3 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2008-01-03 2008-12-31 -0.38 -0.38 -0.94 -0.48 0.12 -0.09
50 2 6 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2008-01-03 2008-12-31 0.79 0.8 1.62 -0.27 0.11 -0.11
51 2 6 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2008-01-03 2008-12-31 0.94 0.95 1.86 -0.17 0.12 -0.09
52 2 6 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 1.01 1.02 1.93 -0.24 0.12 -0.08
53 2 6 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 0.27 0.27 0.8 -0.25 0.12 -0.09
54 2 6 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2008-01-03 2008-12-31 -0.05 -0.05 0.09 -0.32 0.12 -0.09
55 2 6 Months ts_wavenet_gru_^GSPC No ^GSPC Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 -0.14 -0.14 -0.17 -0.34 0.12 -0.09
56 2 6 Months ts_wavenet_lstm_^GSPC No ^GSPC Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 0.1 0.1 0.43 -0.35 0.12 -0.09
57 2 6 Months ts_gru_2_^GSPC No ^GSPC Market 1 gru AI ... 2008-01-03 2008-12-31 0.79 0.8 1.62 -0.27 0.11 -0.11
58 2 6 Months all_All_^GSPC No ^GSPC Market 8 composite ... 2008-01-03 2008-12-31 0.67 0.68 1.53 -0.21 0.12 -0.08
61 2 6 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2008-01-03 2008-12-31 -0.38 -0.38 -0.94 -0.48 0.12 -0.09

20 rows × 23 columns

Persist Backtest to DB (optional )

In [84]:
session.add( tsExecuteEngine )

try :
    session.commit()
except Exception as inst:
    print(type(inst))    # the exception instance
    print(inst)
    print(inst.args)     # arguments stored in .args
    session.rollback()   # roll back changes
finally:
    print(" done")
 done

SW-WFA-Backtest 2

Description:

  • Training-set is not anchored in outer slide window or during a backtest
  • Same trade strategies as Portfolio F
  • Re-fit AI trading models every 3 months within a backtest
  • Fixed Training and Validation periods
  • Training-set is not anchored in outer slide window or during a backtest
  • $200K/strategy

Backtest:

1. Type: Slide Window WFA Backtest

2. Start AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2000-01-01 
        2. End Date   = 2005-12-31  
    2. Validation Period: 
        1. Begin Date = 2006-01-01 
        2. End Date   = 2007-12-31 

3. Final AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2004-01-01 
        2. End Date   = 2009-12-31  
    2. Validation Period: 
        1. Begin Date = 2010-01-01 
        2. End Date   = 2011-12-31   

4. Start Test Period: 
    1. Begin Date = 2008-01-01 
    2. End Date   = 2008-12-31

5. Final Test Period: 
    1. Begin Date = 2012-01-01 
    2. End Date   = 2012-12-31     

Portfolio Trade Assets

In [21]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [22]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 

Simulation Broker

In [23]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [24]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [25]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "SW-WFA-Backtest 2",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [26]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  30

Training, Validation and Test Periods for Backtest

In [27]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "1999-07-01",
                             strBegDate         = "2000-01-01",
                             strEndDate         = "2005-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2005-07-01",
                               strBegDate         = "2006-01-01",
                               strEndDate         = "2007-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2007-07-01",
                               strBegDate         = "2008-01-01",
                               strEndDate         = "2008-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute Slide Window WFA Backtest

In [28]:
tsExecuteEngine = BacktestExecutionSlideWindowWFA( \
    name                        = "SW-WFA-Backtest 2",
    trade_asset_registered_item = portf_registered_obj,
    wfa_slide_win_size_list     = [ 3 ] , # list of int, associated with wfa_slide_win_period_list                   
    wfa_slide_win_period_list   = [ WFASlideWindowPeriod.Months ],
    wfa_sw_scenario_obj         = WFASlideWinScenarioSlidingDatasets(\
                                        fit_dataset               = fit_datasets,
                                        test_period               = testing_period,
                                        slide_win_size            = 1,
                                        slide_win_period          = WFASlideWindowPeriod.Years,
                                        end_date_last_test_period = datetime(year=2012, month=12, day=31) ),
    anchor_fit_dataset          = False )
In [29]:
tsExecuteEngine.evaluate()
*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 1 ,  WFA SW Name: SW-WFA-Backtest 2      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2008-01-01 00:00:00,  end = 2008-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2000-01-01 00:00:00, end = 2005-12-31 00:00:00     
              validation -- beg = 2006-01-01 00:00:00, end = 2007-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************

before self.wfa_backtest_sum_df len  0
after self.wfa_backtest_sum_df len  31

*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 2 ,  WFA SW Name: SW-WFA-Backtest 2      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2009-01-01 00:00:00,  end = 2009-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2001-01-01 00:00:00, end = 2006-12-31 00:00:00     
              validation -- beg = 2007-01-01 00:00:00, end = 2008-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************

before self.wfa_backtest_sum_df len  31
after self.wfa_backtest_sum_df len  62

*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 3 ,  WFA SW Name: SW-WFA-Backtest 2      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2010-01-01 00:00:00,  end = 2010-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2002-01-01 00:00:00, end = 2007-12-31 00:00:00     
              validation -- beg = 2008-01-01 00:00:00, end = 2009-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-30 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-24 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-14 00:00:00 
****************

before self.wfa_backtest_sum_df len  62
after self.wfa_backtest_sum_df len  93

*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 4 ,  WFA SW Name: SW-WFA-Backtest 2      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2011-01-01 00:00:00,  end = 2011-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2003-01-01 00:00:00, end = 2008-12-31 00:00:00     
              validation -- beg = 2009-01-01 00:00:00, end = 2010-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-29 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-09-19 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-12-13 00:00:00 
****************

before self.wfa_backtest_sum_df len  93
after self.wfa_backtest_sum_df len  124

*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 5 ,  WFA SW Name: SW-WFA-Backtest 2      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2012-01-01 00:00:00,  end = 2012-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2004-01-01 00:00:00, end = 2009-12-31 00:00:00     
              validation -- beg = 2010-01-01 00:00:00, end = 2011-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-02-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-03-28 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-06-22 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-09-18 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-12-14 00:00:00 
****************

before self.wfa_backtest_sum_df len  124
after self.wfa_backtest_sum_df len  155

Backtest Metrics

Save to Excel
In [30]:
tsExecuteEngine.getSummaryMetrics().to_excel("SW-WFA-Backtest-2 backtest-metrics.xlsx")
Performance Metrics
In [31]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')
Out[31]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 1 3 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2008-01-03 2008-12-31 1.72 1.73 2.84 -0.19 0.11 -0.07
2 1 3 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2008-01-03 2008-12-31 1.43 1.44 2.53 -0.22 0.11 -0.07
3 1 3 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 1.39 1.4 2.53 -0.19 0.11 -0.07
4 1 3 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 1.51 1.53 2.67 -0.19 0.11 -0.07
5 1 3 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2008-01-03 2008-12-31 0.77 0.78 1.7 -0.28 0.11 -0.08
6 1 3 Months ts_wavenet_gru_^DJI No ^DJI Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 1.21 1.22 2.32 -0.22 0.11 -0.07
7 1 3 Months ts_wavenet_lstm_^DJI No ^DJI Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 1.5 1.51 2.66 -0.17 0.11 -0.06
8 1 3 Months ts_gru_2_^DJI No ^DJI Market 1 gru AI ... 2008-01-03 2008-12-31 1.72 1.73 2.84 -0.19 0.11 -0.07
9 1 3 Months all_All_^DJI No ^DJI Market 8 composite ... 2008-01-03 2008-12-31 1.35 1.36 2.47 -0.19 0.11 -0.07
30 1 3 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2008-01-03 2008-12-31 -0.33 -0.33 -0.86 -0.42 0.11 -0.08
32 2 3 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2009-01-05 2009-12-31 0.1 0.1 0.52 -0.2 0.07 -0.04
33 2 3 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2009-01-05 2009-12-31 0.41 0.42 1.55 -0.18 0.07 -0.04
34 2 3 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2009-01-05 2009-12-31 -0.11 -0.11 -0.33 -0.26 0.06 -0.08
35 2 3 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2009-01-05 2009-12-31 0.24 0.25 1.03 -0.18 0.07 -0.04
36 2 3 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2009-01-05 2009-12-31 0.13 0.13 0.61 -0.19 0.07 -0.04
37 2 3 Months ts_wavenet_gru_^DJI No ^DJI Market 1 wavenet_gru AI ... 2009-01-05 2009-12-31 0.18 0.18 0.8 -0.19 0.07 -0.04
38 2 3 Months ts_wavenet_lstm_^DJI No ^DJI Market 1 wavenet_lstm AI ... 2009-01-05 2009-12-31 -0.05 -0.06 -0.11 -0.25 0.07 -0.05
39 2 3 Months ts_gru_2_^DJI No ^DJI Market 1 gru AI ... 2009-01-05 2009-12-31 0.1 0.1 0.52 -0.2 0.07 -0.04
40 2 3 Months all_All_^DJI No ^DJI Market 8 composite ... 2009-01-05 2009-12-31 0.36 0.36 1.42 -0.18 0.07 -0.04
61 2 3 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2009-01-05 2009-12-31 0.15 0.16 0.72 -0.27 0.07 -0.05
63 3 3 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2010-01-05 2010-12-31 0.14 0.15 0.91 -0.1 0.04 -0.04
64 3 3 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2010-01-05 2010-12-31 0.03 0.03 0.26 -0.1 0.04 -0.04
65 3 3 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2010-01-05 2010-12-31 0.15 0.16 0.98 -0.11 0.04 -0.04
66 3 3 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2010-01-05 2010-12-31 0.06 0.06 0.45 -0.09 0.04 -0.04
67 3 3 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2010-01-05 2010-12-31 -0.01 -0.01 0.04 -0.15 0.04 -0.04
68 3 3 Months ts_wavenet_gru_^DJI No ^DJI Market 1 wavenet_gru AI ... 2010-01-05 2010-12-31 -0.06 -0.07 -0.33 -0.14 0.04 -0.04
69 3 3 Months ts_wavenet_lstm_^DJI No ^DJI Market 1 wavenet_lstm AI ... 2010-01-05 2010-12-31 -0.1 -0.1 -0.53 -0.13 0.04 -0.04
70 3 3 Months ts_gru_2_^DJI No ^DJI Market 1 gru AI ... 2010-01-05 2010-12-31 0.14 0.15 0.91 -0.1 0.04 -0.04
71 3 3 Months all_All_^DJI No ^DJI Market 8 composite ... 2010-01-05 2010-12-31 0.0 0.0 0.1 -0.13 0.04 -0.04
92 3 3 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2010-01-05 2010-12-31 0.09 0.09 0.64 -0.13 0.04 -0.04
94 4 3 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2011-01-04 2011-12-30 -0.02 -0.02 -0.01 -0.2 0.04 -0.06
95 4 3 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2011-01-04 2011-12-30 0.26 0.26 1.21 -0.15 0.04 -0.06
96 4 3 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2011-01-04 2011-12-30 0.09 0.09 0.53 -0.16 0.04 -0.06
97 4 3 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2011-01-04 2011-12-30 0.09 0.09 0.5 -0.21 0.04 -0.06
98 4 3 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2011-01-04 2011-12-30 -0.02 -0.02 0.0 -0.17 0.04 -0.06
99 4 3 Months ts_wavenet_gru_^DJI No ^DJI Market 1 wavenet_gru AI ... 2011-01-04 2011-12-30 0.32 0.33 1.44 -0.2 0.04 -0.06
100 4 3 Months ts_wavenet_lstm_^DJI No ^DJI Market 1 wavenet_lstm AI ... 2011-01-04 2011-12-30 -0.06 -0.06 -0.19 -0.24 0.04 -0.06
101 4 3 Months ts_gru_2_^DJI No ^DJI Market 1 gru AI ... 2011-01-04 2011-12-30 -0.02 -0.02 -0.01 -0.2 0.04 -0.06
102 4 3 Months all_All_^DJI No ^DJI Market 8 composite ... 2011-01-04 2011-12-30 0.21 0.22 1.04 -0.16 0.04 -0.06
123 4 3 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2011-01-04 2011-12-30 0.05 0.05 0.32 -0.17 0.04 -0.06
125 5 3 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2012-01-04 2012-12-31 -0.04 -0.05 -0.33 -0.1 0.02 -0.02
126 5 3 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2012-01-04 2012-12-31 0.15 0.15 1.24 -0.09 0.02 -0.02
127 5 3 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2012-01-04 2012-12-31 0.2 0.2 1.64 -0.08 0.02 -0.02
128 5 3 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2012-01-04 2012-12-31 0.32 0.32 2.49 -0.08 0.02 -0.02
129 5 3 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2012-01-04 2012-12-31 0.11 0.11 0.96 -0.08 0.02 -0.02
130 5 3 Months ts_wavenet_gru_^DJI No ^DJI Market 1 wavenet_gru AI ... 2012-01-04 2012-12-31 0.11 0.11 0.95 -0.07 0.02 -0.02
131 5 3 Months ts_wavenet_lstm_^DJI No ^DJI Market 1 wavenet_lstm AI ... 2012-01-04 2012-12-31 0.21 0.21 1.73 -0.07 0.02 -0.02
132 5 3 Months ts_gru_2_^DJI No ^DJI Market 1 gru AI ... 2012-01-04 2012-12-31 -0.04 -0.05 -0.33 -0.1 0.02 -0.02
133 5 3 Months all_All_^DJI No ^DJI Market 8 composite ... 2012-01-04 2012-12-31 0.15 0.15 1.24 -0.07 0.02 -0.02
154 5 3 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2012-01-04 2012-12-31 0.06 0.06 0.54 -0.09 0.02 -0.02

50 rows × 23 columns

In [32]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')
Out[32]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
10 1 3 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2008-01-03 2008-12-31 0.3 0.3 0.83 -0.22 0.15 -0.07
11 1 3 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2008-01-03 2008-12-31 0.29 0.29 0.83 -0.22 0.12 -0.08
12 1 3 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 0.51 0.51 1.22 -0.18 0.15 -0.07
13 1 3 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 0.1 0.1 0.44 -0.29 0.12 -0.09
14 1 3 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2008-01-03 2008-12-31 0.37 0.37 0.97 -0.3 0.12 -0.09
15 1 3 Months ts_wavenet_gru_^IXIC No ^IXIC Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 0.02 0.02 0.26 -0.36 0.12 -0.09
16 1 3 Months ts_wavenet_lstm_^IXIC No ^IXIC Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 0.15 0.16 0.55 -0.32 0.12 -0.09
17 1 3 Months ts_gru_2_^IXIC No ^IXIC Market 1 gru AI ... 2008-01-03 2008-12-31 0.3 0.3 0.83 -0.22 0.15 -0.07
18 1 3 Months all_All_^IXIC No ^IXIC Market 8 composite ... 2008-01-03 2008-12-31 0.47 0.47 1.17 -0.23 0.12 -0.07
29 1 3 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2008-01-03 2008-12-31 -0.4 -0.4 -1.02 -0.49 0.12 -0.09
41 2 3 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2009-01-05 2009-12-31 -0.3 -0.3 -1.02 -0.37 0.08 -0.08
42 2 3 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2009-01-05 2009-12-31 0.11 0.11 0.51 -0.2 0.08 -0.06
43 2 3 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2009-01-05 2009-12-31 -0.35 -0.36 -1.25 -0.43 0.08 -0.08
44 2 3 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2009-01-05 2009-12-31 -0.11 -0.11 -0.23 -0.32 0.08 -0.08
45 2 3 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2009-01-05 2009-12-31 -0.05 -0.05 -0.05 -0.23 0.07 -0.07
46 2 3 Months ts_wavenet_gru_^IXIC No ^IXIC Market 1 wavenet_gru AI ... 2009-01-05 2009-12-31 -0.19 -0.2 -0.58 -0.26 0.08 -0.08
47 2 3 Months ts_wavenet_lstm_^IXIC No ^IXIC Market 1 wavenet_lstm AI ... 2009-01-05 2009-12-31 -0.17 -0.17 -0.49 -0.27 0.07 -0.07
48 2 3 Months ts_gru_2_^IXIC No ^IXIC Market 1 gru AI ... 2009-01-05 2009-12-31 -0.3 -0.3 -1.02 -0.37 0.08 -0.08
49 2 3 Months all_All_^IXIC No ^IXIC Market 8 composite ... 2009-01-05 2009-12-31 -0.15 -0.15 -0.41 -0.26 0.08 -0.08
60 2 3 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2009-01-05 2009-12-31 0.39 0.4 1.32 -0.23 0.07 -0.06
72 3 3 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2010-01-05 2010-12-31 -0.14 -0.14 -0.64 -0.28 0.05 -0.04
73 3 3 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2010-01-05 2010-12-31 0.08 0.08 0.49 -0.11 0.05 -0.04
74 3 3 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2010-01-05 2010-12-31 -0.04 -0.04 -0.1 -0.16 0.06 -0.04
75 3 3 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2010-01-05 2010-12-31 0.16 0.16 0.8 -0.16 0.06 -0.04
76 3 3 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2010-01-05 2010-12-31 -0.13 -0.13 -0.53 -0.23 0.05 -0.04
77 3 3 Months ts_wavenet_gru_^IXIC No ^IXIC Market 1 wavenet_gru AI ... 2010-01-05 2010-12-31 -0.15 -0.15 -0.7 -0.23 0.05 -0.04
78 3 3 Months ts_wavenet_lstm_^IXIC No ^IXIC Market 1 wavenet_lstm AI ... 2010-01-05 2010-12-31 -0.05 -0.05 -0.13 -0.12 0.04 -0.04
79 3 3 Months ts_gru_2_^IXIC No ^IXIC Market 1 gru AI ... 2010-01-05 2010-12-31 -0.14 -0.14 -0.64 -0.28 0.05 -0.04
80 3 3 Months all_All_^IXIC No ^IXIC Market 8 composite ... 2010-01-05 2010-12-31 -0.03 -0.03 -0.06 -0.17 0.05 -0.04
91 3 3 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2010-01-05 2010-12-31 0.15 0.15 0.81 -0.17 0.05 -0.04
103 4 3 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2011-01-04 2011-12-30 0.28 0.28 1.06 -0.15 0.06 -0.07
104 4 3 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2011-01-04 2011-12-30 0.51 0.52 1.69 -0.15 0.06 -0.07
105 4 3 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2011-01-04 2011-12-30 0.25 0.25 0.98 -0.1 0.07 -0.07
106 4 3 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2011-01-04 2011-12-30 0.31 0.31 1.16 -0.16 0.06 -0.07
107 4 3 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2011-01-04 2011-12-30 0.06 0.06 0.35 -0.17 0.06 -0.07
108 4 3 Months ts_wavenet_gru_^IXIC No ^IXIC Market 1 wavenet_gru AI ... 2011-01-04 2011-12-30 0.8 0.81 2.37 -0.16 0.06 -0.07
109 4 3 Months ts_wavenet_lstm_^IXIC No ^IXIC Market 1 wavenet_lstm AI ... 2011-01-04 2011-12-30 0.44 0.45 1.54 -0.14 0.06 -0.07
110 4 3 Months ts_gru_2_^IXIC No ^IXIC Market 1 gru AI ... 2011-01-04 2011-12-30 0.28 0.28 1.06 -0.15 0.06 -0.07
111 4 3 Months all_All_^IXIC No ^IXIC Market 8 composite ... 2011-01-04 2011-12-30 0.36 0.37 1.31 -0.15 0.06 -0.07
122 4 3 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2011-01-04 2011-12-30 -0.03 -0.03 -0.0 -0.19 0.05 -0.07
134 5 3 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2012-01-04 2012-12-31 0.01 0.01 0.13 -0.13 0.04 -0.03
135 5 3 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2012-01-04 2012-12-31 -0.01 -0.01 0.04 -0.11 0.03 -0.03
136 5 3 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2012-01-04 2012-12-31 -0.07 -0.07 -0.31 -0.18 0.03 -0.03
137 5 3 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2012-01-04 2012-12-31 -0.04 -0.04 -0.16 -0.18 0.03 -0.03
138 5 3 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2012-01-04 2012-12-31 -0.13 -0.13 -0.73 -0.18 0.03 -0.03
139 5 3 Months ts_wavenet_gru_^IXIC No ^IXIC Market 1 wavenet_gru AI ... 2012-01-04 2012-12-31 -0.11 -0.12 -0.61 -0.18 0.03 -0.04
140 5 3 Months ts_wavenet_lstm_^IXIC No ^IXIC Market 1 wavenet_lstm AI ... 2012-01-04 2012-12-31 -0.07 -0.07 -0.34 -0.15 0.03 -0.03
141 5 3 Months ts_gru_2_^IXIC No ^IXIC Market 1 gru AI ... 2012-01-04 2012-12-31 0.01 0.01 0.13 -0.13 0.04 -0.03
142 5 3 Months all_All_^IXIC No ^IXIC Market 8 composite ... 2012-01-04 2012-12-31 -0.07 -0.07 -0.35 -0.18 0.03 -0.03
153 5 3 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2012-01-04 2012-12-31 0.14 0.14 0.96 -0.12 0.03 -0.03

50 rows × 23 columns

In [33]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')
Out[33]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
19 1 3 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2008-01-03 2008-12-31 0.9 0.91 1.76 -0.27 0.11 -0.11
20 1 3 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2008-01-03 2008-12-31 0.61 0.62 1.39 -0.17 0.12 -0.09
21 1 3 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2008-01-03 2008-12-31 1.68 1.7 2.67 -0.19 0.12 -0.08
22 1 3 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2008-01-03 2008-12-31 0.77 0.77 1.65 -0.2 0.12 -0.09
23 1 3 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2008-01-03 2008-12-31 0.1 0.1 0.44 -0.32 0.12 -0.09
24 1 3 Months ts_wavenet_gru_^GSPC No ^GSPC Market 1 wavenet_gru AI ... 2008-01-03 2008-12-31 0.26 0.26 0.76 -0.26 0.12 -0.09
25 1 3 Months ts_wavenet_lstm_^GSPC No ^GSPC Market 1 wavenet_lstm AI ... 2008-01-03 2008-12-31 0.19 0.19 0.63 -0.35 0.12 -0.09
26 1 3 Months ts_gru_2_^GSPC No ^GSPC Market 1 gru AI ... 2008-01-03 2008-12-31 0.9 0.91 1.76 -0.27 0.11 -0.11
27 1 3 Months all_All_^GSPC No ^GSPC Market 8 composite ... 2008-01-03 2008-12-31 1.62 1.63 2.59 -0.19 0.12 -0.08
28 1 3 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2008-01-03 2008-12-31 -0.38 -0.38 -0.94 -0.48 0.12 -0.09
50 2 3 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2009-01-05 2009-12-31 0.15 0.15 0.63 -0.18 0.07 -0.05
51 2 3 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2009-01-05 2009-12-31 0.09 0.1 0.47 -0.22 0.07 -0.05
52 2 3 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2009-01-05 2009-12-31 0.24 0.24 0.93 -0.23 0.06 -0.07
53 2 3 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2009-01-05 2009-12-31 -0.01 -0.01 0.13 -0.29 0.06 -0.07
54 2 3 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2009-01-05 2009-12-31 0.19 0.19 0.77 -0.28 0.07 -0.05
55 2 3 Months ts_wavenet_gru_^GSPC No ^GSPC Market 1 wavenet_gru AI ... 2009-01-05 2009-12-31 0.13 0.13 0.58 -0.28 0.07 -0.05
56 2 3 Months ts_wavenet_lstm_^GSPC No ^GSPC Market 1 wavenet_lstm AI ... 2009-01-05 2009-12-31 0.2 0.2 0.81 -0.28 0.07 -0.05
57 2 3 Months ts_gru_2_^GSPC No ^GSPC Market 1 gru AI ... 2009-01-05 2009-12-31 0.15 0.15 0.63 -0.18 0.07 -0.05
58 2 3 Months all_All_^GSPC No ^GSPC Market 8 composite ... 2009-01-05 2009-12-31 0.37 0.37 1.34 -0.22 0.07 -0.05
59 2 3 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2009-01-05 2009-12-31 0.2 0.2 0.8 -0.28 0.07 -0.05
81 3 3 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2010-01-05 2010-12-31 -0.06 -0.06 -0.27 -0.17 0.04 -0.04
82 3 3 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2010-01-05 2010-12-31 0.27 0.27 1.4 -0.13 0.04 -0.03
83 3 3 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2010-01-05 2010-12-31 0.16 0.16 0.9 -0.11 0.04 -0.04
84 3 3 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2010-01-05 2010-12-31 0.38 0.38 1.89 -0.1 0.04 -0.04
85 3 3 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2010-01-05 2010-12-31 0.29 0.29 1.47 -0.12 0.04 -0.04
86 3 3 Months ts_wavenet_gru_^GSPC No ^GSPC Market 1 wavenet_gru AI ... 2010-01-05 2010-12-31 -0.08 -0.08 -0.36 -0.17 0.04 -0.04
87 3 3 Months ts_wavenet_lstm_^GSPC No ^GSPC Market 1 wavenet_lstm AI ... 2010-01-05 2010-12-31 0.26 0.26 1.36 -0.14 0.04 -0.03
88 3 3 Months ts_gru_2_^GSPC No ^GSPC Market 1 gru AI ... 2010-01-05 2010-12-31 -0.06 -0.06 -0.27 -0.17 0.04 -0.04
89 3 3 Months all_All_^GSPC No ^GSPC Market 8 composite ... 2010-01-05 2010-12-31 0.22 0.22 1.25 -0.07 0.04 -0.04
90 3 3 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2010-01-05 2010-12-31 0.11 0.11 0.67 -0.16 0.04 -0.04
112 4 3 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2011-01-04 2011-12-30 0.14 0.14 0.66 -0.19 0.05 -0.07
113 4 3 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2011-01-04 2011-12-30 0.03 0.03 0.25 -0.14 0.05 -0.07
114 4 3 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2011-01-04 2011-12-30 0.31 0.32 1.28 -0.21 0.05 -0.07
115 4 3 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2011-01-04 2011-12-30 0.05 0.05 0.32 -0.18 0.05 -0.07
116 4 3 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2011-01-04 2011-12-30 0.16 0.16 0.75 -0.17 0.05 -0.07
117 4 3 Months ts_wavenet_gru_^GSPC No ^GSPC Market 1 wavenet_gru AI ... 2011-01-04 2011-12-30 0.18 0.18 0.81 -0.15 0.05 -0.07
118 4 3 Months ts_wavenet_lstm_^GSPC No ^GSPC Market 1 wavenet_lstm AI ... 2011-01-04 2011-12-30 0.04 0.04 0.29 -0.2 0.05 -0.07
119 4 3 Months ts_gru_2_^GSPC No ^GSPC Market 1 gru AI ... 2011-01-04 2011-12-30 0.14 0.14 0.66 -0.19 0.05 -0.07
120 4 3 Months all_All_^GSPC No ^GSPC Market 8 composite ... 2011-01-04 2011-12-30 0.25 0.26 1.08 -0.15 0.05 -0.07
121 4 3 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2011-01-04 2011-12-30 -0.01 -0.01 0.07 -0.19 0.05 -0.07
143 5 3 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2012-01-04 2012-12-31 0.01 0.01 0.18 -0.13 0.02 -0.03
144 5 3 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2012-01-04 2012-12-31 0.08 0.08 0.69 -0.09 0.02 -0.02
145 5 3 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2012-01-04 2012-12-31 0.06 0.06 0.51 -0.08 0.03 -0.03
146 5 3 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2012-01-04 2012-12-31 0.17 0.17 1.31 -0.07 0.03 -0.02
147 5 3 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2012-01-04 2012-12-31 0.19 0.19 1.44 -0.08 0.03 -0.02
148 5 3 Months ts_wavenet_gru_^GSPC No ^GSPC Market 1 wavenet_gru AI ... 2012-01-04 2012-12-31 0.03 0.03 0.28 -0.17 0.02 -0.02
149 5 3 Months ts_wavenet_lstm_^GSPC No ^GSPC Market 1 wavenet_lstm AI ... 2012-01-04 2012-12-31 0.11 0.11 0.9 -0.08 0.03 -0.02
150 5 3 Months ts_gru_2_^GSPC No ^GSPC Market 1 gru AI ... 2012-01-04 2012-12-31 0.01 0.01 0.18 -0.13 0.02 -0.03
151 5 3 Months all_All_^GSPC No ^GSPC Market 8 composite ... 2012-01-04 2012-12-31 -0.06 -0.06 -0.43 -0.11 0.02 -0.02
152 5 3 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2012-01-04 2012-12-31 0.12 0.12 0.94 -0.1 0.02 -0.02

50 rows × 23 columns

SW-WFA-Backtest 3

Description:

  • Portfolio has all the trade strategies in Portfolio G
  • Re-fit AI trading models every 3 months within a backtest and anchored within the backtest
  • Fit datasets are anchored and duration increased by one year increments for five consecutive years
    • Every sliding window iteration, the training set duration is increased by 9 months and the validation set by 3 months, the test set is just shifted by one year.
  • Training-set is anchored in outer slide window and also anchored in the re-fitting process during a backtest
  • $200K/strategy

Backtest:

  • Type: Slide Window WFA Backtest

  • Iteration 1:

       train:       1/1/1995 to 12/31/2000
       validation:  1/1/2001 to 12/31/2002
       Test Period: 1/1/2003 to 12/31/2003
  • Iteration 2:

       train:        1/1/1995  to  9/30/2001    (date range increased by nine-months)
       validation:  10/1/2001  to 12/31/2003    (date range increased by three-months and shifted 
                                                 by nine-months)
       Test Period:  1/1/2004  to 12/31/2004    (date range shifted by one-year)
  • Iteration 3:

       train:        1/1/1995  to  6/30/2002    (date range increased by nine-months)
       validation:   7/1/2002  to 12/31/2004    (date range increaed by three-months and shifted
                                                 by nine-months)
       Test Period:  1/1/2005  to 12/31/2005    (date range shifted by one-year)
    
       ...
       ...
  • Iteration Last:

       train:       1/1/2000 to xxx
       validation:  yyy      to 12/31/2006       
       Test Period: 1/1/2007 to 12/31/2007   
  • Each iteration corresponds to a WFA Backtest, and in each WFA Backtest, AI Models are re-fitted every three months with the training and validation set for the WFA backtest anchored.

Portfolio Trade Assets

In [5]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [6]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 

Simulation Broker

In [7]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [8]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },

                               "stop_lost" :
                                    { 'model'    : "fix_perc",
                                      'type'     : "ta",
                                      'obj_args' : { 'long_stop_los_per' : 5, 'short_stop_los_per'    : 5 }  } 
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'  : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #7
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'      : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

# TS #9

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #11

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_bb",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "bb",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 13, 'window_dev' : 1 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #12

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_macd",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 26, 'window_fast' : 12, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #13

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_rsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "rsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'rsi_enter_long'  : 30.0,  'rsi_exit_long'  : 30.0, 
                                                 'rsi_enter_short' : 70.0,  'rsi_exit_short' : 70.0 },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #14

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_srsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "srsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 14,  'smooth1' : 3, 'smooth2'  : 3,
                                                 'srsi_enter_long'  : 0.8,  'srsi_exit_long'  : 0.8,
                                                 'srsi_enter_short' : 0.2,  'srsi_exit_short' : 0.2 },
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #15

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_adx",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "adx",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'adx_enter_long_ge' : 14, 'adx_exit_long_lt'  : 14,
                                             'adx_enter_short_ge' : 14, 'adx_exit_short_lt' : 14 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #16

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #17

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #18

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_forceindex",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "forceindex",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 39 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #19

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_mfi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "mfi",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'long_slope_win' : 15, 'short_slope_win' : 15 },
                              'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [9]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "SW-WFA-Backtest 3",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [10]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  63

Training, Validation and Test Periods for Backtest

In [11]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "1994-07-01",
                             strBegDate         = "1995-01-01",
                             strEndDate         = "2000-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2000-07-01",
                               strBegDate         = "2001-01-01",
                               strEndDate         = "2002-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2002-07-01",
                               strBegDate         = "2003-01-01",
                               strEndDate         = "2003-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute Slide Window WFA Backtest

In [12]:
tsExecuteEngine = BacktestExecutionSlideWindowWFA( \
    name                        = "SW-WFA-Backtest 3",
    trade_asset_registered_item = portf_registered_obj,
    wfa_slide_win_size_list     = [ 3 ] , # list of int, associated with wfa_slide_win_period_list                   
    wfa_slide_win_period_list   = [ WFASlideWindowPeriod.Months ],
    wfa_sw_scenario_obj         = WFASlideWinScenarioAnchoredSlidingDatasets(\
                                        fit_dataset               = fit_datasets,
                                        test_period               = testing_period,
                                        train_slide_win_size      = 9, # increase train set 9 months every sw incr
                                        val_slide_win_size        = 3, # increase val set 3 months every sw incr
                                                                       # and shift by 9 months
                                        slide_win_period          = WFASlideWindowPeriod.Months,
                                        end_date_last_test_period = datetime(year=2007, month=12, day=31) ),
    anchor_fit_dataset          = True )
In [13]:
tsExecuteEngine.evaluate()
*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 1 ,  WFA SW Name: SW-WFA-Backtest 3      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : True           
***          WFA SW Scenario Name : WFASlideWinScenarioAnchoredSlidingDatasets             
***
        -- Test Period                              
              beg = 2003-01-01 00:00:00,  end = 2003-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1995-01-01 00:00:00, end = 2000-12-31 00:00:00     
              validation -- beg = 2001-01-01 00:00:00, end = 2002-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 2 ,  WFA SW Name: SW-WFA-Backtest 3      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : True           
***          WFA SW Scenario Name : WFASlideWinScenarioAnchoredSlidingDatasets             
***
        -- Test Period                              
              beg = 2004-01-01 00:00:00,  end = 2004-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1995-01-01 00:00:00, end = 2001-09-30 00:00:00     
              validation -- beg = 2001-10-01 00:00:00, end = 2003-12-30 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-29 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-24 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 3 ,  WFA SW Name: SW-WFA-Backtest 3      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : True           
***          WFA SW Scenario Name : WFASlideWinScenarioAnchoredSlidingDatasets             
***
        -- Test Period                              
              beg = 2005-01-01 00:00:00,  end = 2005-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1995-01-01 00:00:00, end = 2002-06-30 00:00:00     
              validation -- beg = 2002-07-01 00:00:00, end = 2004-12-30 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-30 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-19 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 4 ,  WFA SW Name: SW-WFA-Backtest 3      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : True           
***          WFA SW Scenario Name : WFASlideWinScenarioAnchoredSlidingDatasets             
***
        -- Test Period                              
              beg = 2006-01-01 00:00:00,  end = 2006-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1995-01-01 00:00:00, end = 2003-03-30 00:00:00     
              validation -- beg = 2003-04-01 00:00:00, end = 2005-12-30 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-29 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-23 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-09-19 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 5 ,  WFA SW Name: SW-WFA-Backtest 3      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 3 
***          Anchor Start Fit Date  : True           
***          WFA SW Scenario Name : WFASlideWinScenarioAnchoredSlidingDatasets             
***
        -- Test Period                              
              beg = 2007-01-01 00:00:00,  end = 2007-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1995-01-01 00:00:00, end = 2003-12-30 00:00:00     
              validation -- beg = 2004-01-01 00:00:00, end = 2006-12-30 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-29 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-06-25 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-09-19 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-12-13 00:00:00 
****************

Backtest Metrics

Save to Excel
In [14]:
tsExecuteEngine.getSummaryMetrics().to_excel("SW-WFA-Backtest-3 backtest-metrics.xlsx")
DJI
In [15]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')
Out[15]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 1 3 Months ts_gru_1_^DJI No ^DJI Market 1 gru AI ... 2003-01-03 2003-12-31 0.23 0.24 1.37 -0.1 0.04 -0.03
2 1 3 Months ts_lstm_^DJI No ^DJI Market 1 lstm AI ... 2003-01-03 2003-12-31 0.14 0.14 0.89 -0.15 0.04 -0.03
3 1 3 Months ts_conv1d_gru_^DJI No ^DJI Market 1 conv1d_gru AI ... 2003-01-03 2003-12-31 0.07 0.07 0.49 -0.16 0.04 -0.04
4 1 3 Months ts_conv1d_lstm_^DJI No ^DJI Market 1 conv1d_lstm AI ... 2003-01-03 2003-12-31 0.16 0.17 1.02 -0.15 0.04 -0.04
5 1 3 Months ts_wavenet_^DJI No ^DJI Market 1 wavenet AI ... 2003-01-03 2003-12-31 -0.12 -0.12 -0.68 -0.18 0.04 -0.03
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
273 5 3 Months ts_tsi_^DJI No ^DJI Market 1 tsi TA ... 2007-01-04 2007-12-31 -0.15 -0.15 -1.1 -0.19 0.03 -0.03
274 5 3 Months ts_forceindex_^DJI No ^DJI Market 1 forceindex TA ... 2007-01-04 2007-12-31 -0.13 -0.13 -1.0 -0.16 0.03 -0.03
275 5 3 Months ts_mfi_^DJI No ^DJI Market 1 mfi TA ... 2007-01-04 2007-12-31 0.1 0.1 0.93 -0.07 0.03 -0.02
276 5 3 Months all_All_^DJI No ^DJI Market 19 composite ... 2007-01-04 2007-12-31 -0.01 -0.01 0.03 -0.1 0.03 -0.02
318 5 3 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2007-01-04 2007-12-31 0.06 0.06 0.5 -0.1 0.03 -0.03

105 rows × 23 columns

Nasdaq
In [16]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')
Out[16]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
21 1 3 Months ts_gru_1_^IXIC No ^IXIC Market 1 gru AI ... 2003-01-03 2003-12-31 0.05 0.05 0.32 -0.17 0.05 -0.04
22 1 3 Months ts_lstm_^IXIC No ^IXIC Market 1 lstm AI ... 2003-01-03 2003-12-31 0.32 0.32 1.35 -0.13 0.05 -0.04
23 1 3 Months ts_conv1d_gru_^IXIC No ^IXIC Market 1 conv1d_gru AI ... 2003-01-03 2003-12-31 -0.07 -0.07 -0.2 -0.16 0.05 -0.04
24 1 3 Months ts_conv1d_lstm_^IXIC No ^IXIC Market 1 conv1d_lstm AI ... 2003-01-03 2003-12-31 -0.04 -0.04 -0.05 -0.14 0.05 -0.04
25 1 3 Months ts_wavenet_^IXIC No ^IXIC Market 1 wavenet AI ... 2003-01-03 2003-12-31 -0.2 -0.2 -0.85 -0.25 0.05 -0.04
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
293 5 3 Months ts_tsi_^IXIC No ^IXIC Market 1 tsi TA ... 2007-01-04 2007-12-31 -0.13 -0.13 -0.71 -0.17 0.03 -0.04
294 5 3 Months ts_forceindex_^IXIC No ^IXIC Market 1 forceindex TA ... 2007-01-04 2007-12-31 -0.14 -0.14 -0.82 -0.17 0.03 -0.04
295 5 3 Months ts_mfi_^IXIC No ^IXIC Market 1 mfi TA ... 2007-01-04 2007-12-31 -0.04 -0.04 -0.22 -0.1 0.03 -0.03
296 5 3 Months all_All_^IXIC No ^IXIC Market 19 composite ... 2007-01-04 2007-12-31 -0.03 -0.03 -0.12 -0.1 0.03 -0.04
317 5 3 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2007-01-04 2007-12-31 0.09 0.1 0.61 -0.11 0.03 -0.04

105 rows × 23 columns

S&P 500
In [17]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')
Out[17]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
41 1 3 Months ts_gru_1_^GSPC No ^GSPC Market 1 gru AI ... 2003-01-03 2003-12-31 0.17 0.17 1.01 -0.14 0.04 -0.04
42 1 3 Months ts_lstm_^GSPC No ^GSPC Market 1 lstm AI ... 2003-01-03 2003-12-31 0.14 0.14 0.87 -0.14 0.04 -0.04
43 1 3 Months ts_conv1d_gru_^GSPC No ^GSPC Market 1 conv1d_gru AI ... 2003-01-03 2003-12-31 0.13 0.13 0.81 -0.13 0.04 -0.03
44 1 3 Months ts_conv1d_lstm_^GSPC No ^GSPC Market 1 conv1d_lstm AI ... 2003-01-03 2003-12-31 0.22 0.23 1.29 -0.14 0.04 -0.04
45 1 3 Months ts_wavenet_^GSPC No ^GSPC Market 1 wavenet AI ... 2003-01-03 2003-12-31 -0.22 -0.22 -1.23 -0.22 0.04 -0.03
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
313 5 3 Months ts_tsi_^GSPC No ^GSPC Market 1 tsi TA ... 2007-01-04 2007-12-31 -0.15 -0.16 -1.04 -0.19 0.03 -0.03
314 5 3 Months ts_forceindex_^GSPC No ^GSPC Market 1 forceindex TA ... 2007-01-04 2007-12-31 -0.19 -0.2 -1.38 -0.22 0.03 -0.03
315 5 3 Months ts_mfi_^GSPC No ^GSPC Market 1 mfi TA ... 2007-01-04 2007-12-31 0.05 0.05 0.42 -0.09 0.03 -0.03
316 5 3 Months all_All_^GSPC No ^GSPC Market 19 composite ... 2007-01-04 2007-12-31 0.04 0.04 0.31 -0.08 0.03 -0.03
319 5 3 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2007-01-04 2007-12-31 0.04 0.04 0.31 -0.1 0.03 -0.03

105 rows × 23 columns

SW-WFA-Backtest 4

Description:

  • Portfolio has all the trade strategies in Portfolio G and C
  • Five Stop-Models are added utilized
    • One model with fix values for stop-loss and trail-stop loss
    • Four ATR models, each configured with different hyper parameters
  • Every trade strategy in Portfolio C, and G, for each of their Enter/Exit Models is evaluated with each stop-model, including the composite Enter/Exit models
  • The total number of permutations of all trade strategies for all securities, enter/exit models, stop models, and ensemble models is 633
  • Re-fit AI trading models every 4 and 12 months within a backtest and not anchored within the backtest
  • Training-set is not anchored in outer slide window and also not anchored in the re-fitting process during a backtest
  • $200K/strategy

Backtest:

  • Type: Slide Window WFA Backtest

  • Iteration 1:

       train:       1/1/1994 to 12/31/1998
       validation:  1/1/1999 to 12/31/2000
       Test Period: 1/1/2001 to 12/31/2001
    
       ...
       ...
  • Iteration Last:

       train:       1/1/2003 to 12/31/2007
       validation:  1/1/2008 to 12/31/2009       
       Test Period: 1/1/2010 to 12/31/2010   

Portfolio Trade Assets

In [18]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [19]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        forceCreateMarketData = False,
        interval               = "1d"  ) 

Simulation Broker

In [21]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [22]:
tsConfDat_SuperSet = TradeStrategyConfigData()

# Set Config

tsConfDat_SuperSet.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )          
# TS #1

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "TA" ],
          'ts_unique_tag'  : "ts_macd_1",    
          'actions_conf'   : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 18, 'window_fast' : 7, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #2

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "TA" ],
          'ts_unique_tag' : "ts_bb_1",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "bb",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 7, 'window_dev' : 1 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #3

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "TA" ],
          'ts_unique_tag' : "ts_sma_1x",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #4

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "TA" ],
          'ts_unique_tag' : "ts_macd_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "macd",
                                  'type'     : "ta",
                                  'obj_args' : { 'window_slow' : 26, 'window_fast' : 12, 'window_sign' : 9,
                                                 'enter_long_macd_diff'  : 0.5 , 'exi_long_macd_diff' : 0.5,
                                                 'enter_short_macd_diff' : -0.5, 'exi_short_macd_diff' : -0.5  },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #5

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "TA" ],
          'ts_unique_tag' : "ts_rsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "rsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'rsi_enter_long'  : 30.0,  'rsi_exit_long'  : 30.0, 
                                                 'rsi_enter_short' : 70.0,  'rsi_exit_short' : 70.0 },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #6

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "TA" ],
          'ts_unique_tag' : "ts_srsi",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "srsi",
                                  'type'     : "ta",
                                  'obj_args' : { 'window' : 14,  'smooth1' : 3, 'smooth2'  : 3,
                                                 'srsi_enter_long'  : 0.8,  'srsi_exit_long'  : 0.8,
                                                 'srsi_enter_short' : 0.2,  'srsi_exit_short' : 0.2 },
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )
# TS #7

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
      'set_categories' : [ "TA" ],
      'ts_unique_tag' : "ts_adx",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "adx",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'adx_enter_long_ge' : 14, 'adx_exit_long_lt'  : 14,
                                             'adx_enter_short_ge' : 14, 'adx_exit_short_lt' : 14 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #8

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
      'set_categories' : [ "TA" ],
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #9

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
      'set_categories' : [ "TA" ],
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #10

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
      'set_categories' : [ "TA" ],
      'ts_unique_tag' : "ts_forceindex",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "forceindex",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 39 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

# TS #11

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
      'set_categories' : [ "TA" ],
      'ts_unique_tag' : "ts_mfi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "mfi",
                              'type'     : "ta",
                              'obj_args' : { 'window' : 14, 'long_slope_win' : 15, 'short_slope_win' : 15 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )


# TS #12

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_gru_1", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #13

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #14
    
tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #15
tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_conv1d_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #16

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_wavenet", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #17

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_wavenet_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #18
tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_wavenet_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "wavenet_lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #19
tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "AI" ],
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 40,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
           
# TS #20

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #21

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_2",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )


# TS #22


tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_3",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 13, 'win_slow' : 65 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #23

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_4",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #24

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_5",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 75 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #25

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_6",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #26

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_7",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 12, 'win_slow' : 40 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )


# TS #27

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_8",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 17, 'win_slow' : 80 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #28

tsConfDat_SuperSet.addTSConf(\
   ts_conf_dict = { 
          'set_categories' : [ "SMA" ],
          'ts_unique_tag' : "ts_sma_9",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 22, 'win_slow' : 90 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

Risk-Stop-Loss Models

In [23]:
# ***
# *** Configure Several Types of Stop Actions
# ***
#      order_type = 1 ( Stop-Loss )
#      order_type = 2 ( Trail-Stop-Loss )
#      order_type = 3 ( Combine Stop-Loss & Trail-Stop-Loss )
#
# Stop Models :
#       fixval { user-defined stop-loss-percent and/or trail-stop-loss-percent }
#       atr    { uses ATR model to dynamically determined the stop and trail stop loss percents }

# *** Stop-Loss Order Type

tsStopsConfDat_Stop_Loss = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 1 } }
           } )
           
# 1) *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Fixed Values

tsStopsConfDat_Stop_Loss_And_Trail_SL_1 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_1.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_1.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# 2) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_2 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_2.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_2.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_2",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                               },
                                },
                             },
                   }  )

# 3) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_3 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_3.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_3.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_3",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.01,
                                                 'trail_stop_loss_mult'    : 0.03,
                                               },
                                },
                             },
                   }  )

# *4) **

tsStopsConfDat_Stop_Loss_And_Trail_SL_4 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_4.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_4.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_4",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.0075,
                                                 'trail_stop_loss_mult'    : 0.0095,
                                               },
                                },
                             },
                   }  )

# 5) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_5 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_5.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_5.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_5",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.0025,
                                                 'trail_stop_loss_mult'    : 0.0050,
                                               },
                                },
                             },
                   }  )

stopsConfDatList = [ tsStopsConfDat_Stop_Loss_And_Trail_SL_1, tsStopsConfDat_Stop_Loss_And_Trail_SL_2,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_3, tsStopsConfDat_Stop_Loss_And_Trail_SL_4,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_5
                   ]

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [24]:
 
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "SW-WFA-Backtest 4",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat_SuperSet,
                           stop_config_models       = stopsConfDatList,
                           set_cats                 = [ "All", "TA", "AI", "SMA", 
                                                        ["TA", "AI"], ["TA", "SMA"], ["AI", "SMA"] ],

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [25]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  633

Training, Validation, and Test Periods - Start Date Ranges

In [26]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "1993-07-01",
                             strBegDate         = "1994-01-01",
                             strEndDate         = "1998-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "1998-07-01",
                               strBegDate         = "1999-01-01",
                               strEndDate         = "2000-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2000-07-01",
                               strBegDate         = "2001-01-01",
                               strEndDate         = "2001-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute Backtest

In [27]:
tsExecuteEngine = BacktestExecutionSlideWindowWFA( \
    name                        = "SW-WFA-Backtest 4",
    trade_asset_registered_item = portf_registered_obj,
    wfa_slide_win_size_list     = [ 4, 12 ] , # list of int, associated with wfa_slide_win_period_list                   
    wfa_slide_win_period_list   = [ WFASlideWindowPeriod.Months, WFASlideWindowPeriod.Months ],
    wfa_sw_scenario_obj         = WFASlideWinScenarioSlidingDatasets(\
                                        fit_dataset               = fit_datasets,
                                        test_period               = testing_period,
                                        slide_win_size            = 1,
                                        slide_win_period          = WFASlideWindowPeriod.Years,
                                        end_date_last_test_period = datetime(year=2010, month=12, day=31) ),
    anchor_fit_dataset          = False )
In [28]:
tsExecuteEngine.evaluate()
*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 1 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2001-01-01 00:00:00,  end = 2001-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1994-01-01 00:00:00, end = 1998-12-31 00:00:00     
              validation -- beg = 1999-01-01 00:00:00, end = 2000-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 2 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2001-01-01 00:00:00,  end = 2001-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1994-01-01 00:00:00, end = 1998-12-31 00:00:00     
              validation -- beg = 1999-01-01 00:00:00, end = 2000-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 3 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2002-01-01 00:00:00,  end = 2002-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1995-01-01 00:00:00, end = 1999-12-31 00:00:00     
              validation -- beg = 2000-01-01 00:00:00, end = 2001-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-26 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 4 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2002-01-01 00:00:00,  end = 2002-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1995-01-01 00:00:00, end = 1999-12-31 00:00:00     
              validation -- beg = 2000-01-01 00:00:00, end = 2001-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 5 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2003-01-01 00:00:00,  end = 2003-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1996-01-01 00:00:00, end = 2000-12-31 00:00:00     
              validation -- beg = 2001-01-01 00:00:00, end = 2002-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 6 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2003-01-01 00:00:00,  end = 2003-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1996-01-01 00:00:00, end = 2000-12-31 00:00:00     
              validation -- beg = 2001-01-01 00:00:00, end = 2002-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 7 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2004-01-01 00:00:00,  end = 2004-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1997-01-01 00:00:00, end = 2001-12-31 00:00:00     
              validation -- beg = 2002-01-01 00:00:00, end = 2003-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-27 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 8 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2004-01-01 00:00:00,  end = 2004-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1997-01-01 00:00:00, end = 2001-12-31 00:00:00     
              validation -- beg = 2002-01-01 00:00:00, end = 2003-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 9 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2005-01-01 00:00:00,  end = 2005-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1998-01-01 00:00:00, end = 2002-12-31 00:00:00     
              validation -- beg = 2003-01-01 00:00:00, end = 2004-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-27 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-19 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 10 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2005-01-01 00:00:00,  end = 2005-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1998-01-01 00:00:00, end = 2002-12-31 00:00:00     
              validation -- beg = 2003-01-01 00:00:00, end = 2004-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 11 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2006-01-01 00:00:00,  end = 2006-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1999-01-01 00:00:00, end = 2003-12-31 00:00:00     
              validation -- beg = 2004-01-01 00:00:00, end = 2005-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-04-27 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-08-21 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 12 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2006-01-01 00:00:00,  end = 2006-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1999-01-01 00:00:00, end = 2003-12-31 00:00:00     
              validation -- beg = 2004-01-01 00:00:00, end = 2005-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 13 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2007-01-01 00:00:00,  end = 2007-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2000-01-01 00:00:00, end = 2004-12-31 00:00:00     
              validation -- beg = 2005-01-01 00:00:00, end = 2006-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-04-27 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-06-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-08-21 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 14 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2007-01-01 00:00:00,  end = 2007-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2000-01-01 00:00:00, end = 2004-12-31 00:00:00     
              validation -- beg = 2005-01-01 00:00:00, end = 2006-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-06-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 15 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2008-01-01 00:00:00,  end = 2008-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2001-01-01 00:00:00, end = 2005-12-31 00:00:00     
              validation -- beg = 2006-01-01 00:00:00, end = 2007-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 16 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2008-01-01 00:00:00,  end = 2008-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2001-01-01 00:00:00, end = 2005-12-31 00:00:00     
              validation -- beg = 2006-01-01 00:00:00, end = 2007-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 17 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2009-01-01 00:00:00,  end = 2009-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2002-01-01 00:00:00, end = 2006-12-31 00:00:00     
              validation -- beg = 2007-01-01 00:00:00, end = 2008-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 18 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2009-01-01 00:00:00,  end = 2009-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2002-01-01 00:00:00, end = 2006-12-31 00:00:00     
              validation -- beg = 2007-01-01 00:00:00, end = 2008-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 19 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 4 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2010-01-01 00:00:00,  end = 2010-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2003-01-01 00:00:00, end = 2007-12-31 00:00:00     
              validation -- beg = 2008-01-01 00:00:00, end = 2009-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-28 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-20 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 20 ,  WFA SW Name: SW-WFA-Backtest 4      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 12 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2010-01-01 00:00:00,  end = 2010-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2003-01-01 00:00:00, end = 2007-12-31 00:00:00     
              validation -- beg = 2008-01-01 00:00:00, end = 2009-12-31 00:00:00     

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  Conv1d_LSTM_Model
**** Fitting Model:  WaveNet_Model
**** Fitting Model:  WaveNet_GRU_Model
**** Fitting Model:  WaveNet_LSTM_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-14 00:00:00 
****************

Backtest Metrics

Save to Excel
In [29]:
tsExecuteEngine.getSummaryMetrics().to_excel("SW-WFA-Backtest-4 backtest-metrics.xlsx")
Performance Metrics

DOW

In [30]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')
Out[30]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 1 4 Months ts_macd_1_^DJI No ^DJI Market 1 macd TA ... 2001-01-03 2001-12-31 0.01 0.01 0.13 -0.18 0.06 -0.04
2 1 4 Months ts_bb_1_^DJI No ^DJI Market 1 bb TA ... 2001-01-03 2001-12-31 0.2 0.2 1.17 -0.14 0.04 -0.07
3 1 4 Months ts_sma_1x_^DJI No ^DJI Market 1 sma TA ... 2001-01-03 2001-12-31 0.17 0.17 0.93 -0.11 0.06 -0.04
4 1 4 Months ts_macd_2_^DJI No ^DJI Market 1 macd TA ... 2001-01-03 2001-12-31 0.05 0.05 0.36 -0.13 0.06 -0.04
5 1 4 Months ts_rsi_^DJI No ^DJI Market 1 rsi TA ... 2001-01-03 2001-12-31 -0.1 -0.1 -0.95 -0.14 0.04 -0.07
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
12603 20 12 Months all_SMA_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 9 composite ... atr TA 2010-01-05 2010-12-31 0.54 0.55 4.66 -0.0 0.04 -0.0
12604 20 12 Months all_['TA', 'AI']_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 19 composite ... atr TA 2010-01-05 2010-12-31 0.61 0.62 5.27 -0.0 0.04 -0.0
12605 20 12 Months all_['TA', 'SMA']_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 20 composite ... atr TA 2010-01-05 2010-12-31 0.53 0.54 4.56 -0.0 0.04 -0.0
12606 20 12 Months all_['AI', 'SMA']_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 17 composite ... atr TA 2010-01-05 2010-12-31 0.56 0.57 4.94 -0.0 0.04 -0.0
12678 20 12 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2010-01-05 2010-12-31 0.09 0.09 0.64 -0.13 0.04 -0.04

4220 rows × 23 columns

Nasdaq

In [31]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')
Out[31]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
36 1 4 Months ts_macd_1_^IXIC No ^IXIC Market 1 macd TA ... 2001-01-03 2001-12-31 -0.2 -0.21 -0.35 -0.41 0.08 -0.14
37 1 4 Months ts_bb_1_^IXIC No ^IXIC Market 1 bb TA ... 2001-01-03 2001-12-31 0.02 0.02 0.25 -0.24 0.07 -0.15
38 1 4 Months ts_sma_1x_^IXIC No ^IXIC Market 1 sma TA ... 2001-01-03 2001-12-31 0.01 0.01 0.22 -0.29 0.08 -0.15
39 1 4 Months ts_macd_2_^IXIC No ^IXIC Market 1 macd TA ... 2001-01-03 2001-12-31 0.12 0.12 0.5 -0.32 0.08 -0.14
40 1 4 Months ts_rsi_^IXIC No ^IXIC Market 1 rsi TA ... 2001-01-03 2001-12-31 0.08 0.08 0.53 -0.17 0.09 -0.07
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
12638 20 12 Months all_SMA_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 9 composite ... atr TA 2010-01-05 2010-12-31 0.02 0.02 0.2 -0.06 0.06 -0.05
12639 20 12 Months all_['TA', 'AI']_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 19 composite ... atr TA 2010-01-05 2010-12-31 0.04 0.04 0.33 -0.05 0.04 -0.05
12640 20 12 Months all_['TA', 'SMA']_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 20 composite ... atr TA 2010-01-05 2010-12-31 0.02 0.02 0.2 -0.06 0.04 -0.05
12641 20 12 Months all_['AI', 'SMA']_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 17 composite ... atr TA 2010-01-05 2010-12-31 0.02 0.02 0.2 -0.06 0.06 -0.05
12677 20 12 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2010-01-05 2010-12-31 0.15 0.15 0.81 -0.17 0.05 -0.04

4220 rows × 23 columns

S&P 500

In [32]:
tsExecuteEngine.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')
Out[32]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
71 1 4 Months ts_macd_1_^GSPC No ^GSPC Market 1 macd TA ... 2001-01-03 2001-12-31 0.01 0.01 0.14 -0.17 0.05 -0.04
72 1 4 Months ts_bb_1_^GSPC No ^GSPC Market 1 bb TA ... 2001-01-03 2001-12-31 0.08 0.08 0.54 -0.12 0.04 -0.05
73 1 4 Months ts_sma_1x_^GSPC No ^GSPC Market 1 sma TA ... 2001-01-03 2001-12-31 0.1 0.1 0.59 -0.11 0.04 -0.05
74 1 4 Months ts_macd_2_^GSPC No ^GSPC Market 1 macd TA ... 2001-01-03 2001-12-31 -0.05 -0.05 -0.16 -0.19 0.04 -0.03
75 1 4 Months ts_rsi_^GSPC No ^GSPC Market 1 rsi TA ... 2001-01-03 2001-12-31 -0.03 -0.03 -0.27 -0.13 0.04 -0.05
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
12673 20 12 Months all_SMA_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 9 composite ... atr TA 2010-01-05 2010-12-31 0.48 0.49 3.6 -0.01 0.04 -0.01
12674 20 12 Months all_['TA', 'AI']_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 19 composite ... atr TA 2010-01-05 2010-12-31 0.56 0.57 4.25 -0.01 0.04 -0.01
12675 20 12 Months all_['TA', 'SMA']_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 20 composite ... atr TA 2010-01-05 2010-12-31 0.59 0.6 4.01 -0.01 0.04 -0.01
12676 20 12 Months all_['AI', 'SMA']_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 17 composite ... atr TA 2010-01-05 2010-12-31 0.5 0.51 3.83 -0.01 0.04 -0.01
12679 20 12 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2010-01-05 2010-12-31 0.11 0.11 0.67 -0.16 0.04 -0.04

4220 rows × 23 columns

SW-WFA-Backtest 5

  1. Portfolio K: Long and Multiple Configured SMA Trade Strategies for US Indixes, with Stop Models

    Description:

     1. Seven distinct SMA Trade Strategies for enter/exit a trade, plus an ensemble trade strategy
        of all seven SMA models
     2. Eight different stop-models
         1. Stop Loss order with specified stop-loss percent limit 
         2. Trail Stop Loss order with specified trail-stop-loss percent limit 
         3. Combine Stop-Loss & Trail-Stop-Loss order with specified percent limits
         4-8. Five different Combine Stop-Loss & Trail-Stop-Loss models, configured with dynamic derived
             stop-loss and trail-stop-loss percent limits using Average True Range(ATR) algorithm
     3. $2,000,000/strategy
     3. No-Rebalance during the backtest 
     4. 100% capital invested
     5. Portfolio investment using equal weights for each trade strategy
    
    

    Backtest:

     1. Type: regular
     2. Test Period: 
         1. Begin Date = 2001-01-01 
         2. End Date   = 2020-12-31 

Portfolio Trade Assets

In [33]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [34]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 

Simulation Broker

In [35]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [40]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_1",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 50 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 2, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )


# TS #3


tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_3",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 10, 'win_slow' : 57 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #4

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_4",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #5

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_5",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 75 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #6

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_6",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 7, 'win_slow' : 35 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #7

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_7",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 12, 'win_slow' : 40 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

Risk-Stop-Loss Models

In [41]:
# ***
# *** Configure Several Types of Stop Actions
# ***
#      order_type = 1 ( Stop-Loss )
#      order_type = 2 ( Trail-Stop-Loss )
#      order_type = 3 ( Combine Stop-Loss & Trail-Stop-Loss )
#
# Stop Models :
#       fixval { user-defined stop-loss-percent and/or trail-stop-loss-percent }
#       atr    { uses ATR model to dynamically determined the stop and trail stop loss percents }

# 1) *** Stop-Loss Order Type

tsStopsConfDat_Stop_Loss = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 1 } }
           } )
           
tsStopsConfDat_Stop_Loss.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# 2) *** Trail-Stop-Loss Order Type

tsStopsConfDat_Trail_Stop_Loss = TradeStrategyConfigData()

tsStopsConfDat_Trail_Stop_Loss.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 2} }
           } )
           
tsStopsConfDat_Trail_Stop_Loss.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# 3) *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Fixed Values

tsStopsConfDat_Stop_Loss_And_Trail_SL_1 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_1.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_1.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_fixval",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "fixval",
                                  'type'     : "ta",
                                  'obj_args' : { 'stop_loss_per' : 0.002, 'trail_stop_loss_per' : 0.005 },
                                },
                             },
                   }  )

# 4) *** Combine Stop-Loss & Trail-Stop-Loss Order Type - Using Dynamic Values from ATR

tsStopsConfDat_Stop_Loss_And_Trail_SL_2 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_2.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_2.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_1",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 14, 
                                                 'stop_loss_mult'          : 0.5,
                                                 'trail_stop_loss_mult'    : 1.0,
                                                 'max_stop_loss_per'       : 0.05,
                                                 'min_stop_loss_per'       : 0.002,
                                                 'max_trail_stop_loss_per' : 0.05,
                                                 'min_trail_stop_loss_per' : 0.005,
                                               },
                                },
                             },
                   }  )

# 5) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_3 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_3.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_3.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_2",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                               },
                                },
                             },
                   }  )

# 6) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_4 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_4.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_4.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_3",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.01,
                                                 'trail_stop_loss_mult'    : 0.03,
                                               },
                                },
                             },
                   }  )

# 7) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_5 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_5.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_5.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_4",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                                 'max_stop_loss_per'       : 0.005,
                                                 'min_stop_loss_per'       : 0.002,
                                                 'max_trail_stop_loss_per' : 0.005,
                                                 'min_trail_stop_loss_per' : 0.002,
                                               },
                                },
                             },
                   }  )

# 8) ***

tsStopsConfDat_Stop_Loss_And_Trail_SL_6 = TradeStrategyConfigData()

tsStopsConfDat_Stop_Loss_And_Trail_SL_6.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "stop" : { 'order_type' : 3 } }
           } )
           
tsStopsConfDat_Stop_Loss_And_Trail_SL_6.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "sl_tsl_atr_5",     
          'actions_conf'  : { "stop" :  
                                { 'model'    : "atr",
                                  'type'     : "ta",
                                  'obj_args' : { 'atr_mov_ave'             : 7, 
                                                 'stop_loss_mult'          : 0.05,
                                                 'trail_stop_loss_mult'    : 0.075,
                                                 'max_stop_loss_per'       : 0.005,
                                                 'min_stop_loss_per'       : 0.002,
                                                 'max_trail_stop_loss_per' : 0.01,
                                                 'min_trail_stop_loss_per' : 0.005,
                                               },
                                },
                             },
                   }  )
stopsConfDatList = [ tsStopsConfDat_Stop_Loss,                tsStopsConfDat_Trail_Stop_Loss,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_1, tsStopsConfDat_Stop_Loss_And_Trail_SL_2,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_3, tsStopsConfDat_Stop_Loss_And_Trail_SL_4,
                     tsStopsConfDat_Stop_Loss_And_Trail_SL_5, tsStopsConfDat_Stop_Loss_And_Trail_SL_6
                   ]

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [42]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "SW-WFA-Backtest 5",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,
                           stop_config_models       = stopsConfDatList,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )
In [43]:
print("Number of configured Trade Strategies: ", len(portf_registered_obj.taRegisterItems) )
Number of configured Trade Strategies:  219

Training, Validation, and Test Periods

In [44]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "1997-07-01",
                             strBegDate         = "1998-01-01",
                             strEndDate         = "1999-12-31" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "1999-07-01",
                               strBegDate         = "2000-01-01",
                               strEndDate         = "2000-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2000-07-01",
                               strBegDate         = "2001-01-01",
                               strEndDate         = "2001-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute Backtest

In [45]:
tsExecuteEngine_sw = BacktestExecutionSlideWindowWFA( \
    name                        = "SW-WFA-Backtest 5",
    trade_asset_registered_item = portf_registered_obj,
    wfa_slide_win_size_list     = [ 20 ] , # No use here, no AI Strategies, just TA ones                  
    wfa_slide_win_period_list   = [ WFASlideWindowPeriod.Months ],
    wfa_sw_scenario_obj         = WFASlideWinScenarioSlidingDatasets(\
                                        fit_dataset               = fit_datasets,   # no use in this backtest
                                        test_period               = testing_period,
                                        slide_win_size            = 1,
                                        slide_win_period          = WFASlideWindowPeriod.Years,
                                        end_date_last_test_period = datetime(year=2020, month=12, day=31) ),
    anchor_fit_dataset          = False )
In [46]:
tsExecuteEngine_sw.evaluate()
*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 1 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2001-01-01 00:00:00,  end = 2001-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1998-01-01 00:00:00, end = 1999-12-31 00:00:00     
              validation -- beg = 2000-01-01 00:00:00, end = 2000-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 2 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2002-01-01 00:00:00,  end = 2002-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 1999-01-01 00:00:00, end = 2000-12-31 00:00:00     
              validation -- beg = 2001-01-01 00:00:00, end = 2001-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 3 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2003-01-01 00:00:00,  end = 2003-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2000-01-01 00:00:00, end = 2001-12-31 00:00:00     
              validation -- beg = 2002-01-01 00:00:00, end = 2002-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 4 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2004-01-01 00:00:00,  end = 2004-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2001-01-01 00:00:00, end = 2002-12-31 00:00:00     
              validation -- beg = 2003-01-01 00:00:00, end = 2003-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 5 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2005-01-01 00:00:00,  end = 2005-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2002-01-01 00:00:00, end = 2003-12-31 00:00:00     
              validation -- beg = 2004-01-01 00:00:00, end = 2004-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 6 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2006-01-01 00:00:00,  end = 2006-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2003-01-01 00:00:00, end = 2004-12-31 00:00:00     
              validation -- beg = 2005-01-01 00:00:00, end = 2005-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2006-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 7 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2007-01-01 00:00:00,  end = 2007-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2004-01-01 00:00:00, end = 2005-12-31 00:00:00     
              validation -- beg = 2006-01-01 00:00:00, end = 2006-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-06-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2007-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 8 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2008-01-01 00:00:00,  end = 2008-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2005-01-01 00:00:00, end = 2006-12-31 00:00:00     
              validation -- beg = 2007-01-01 00:00:00, end = 2007-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-04-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-05-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2008-12-11 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 9 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2009-01-01 00:00:00,  end = 2009-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2006-01-01 00:00:00, end = 2007-12-31 00:00:00     
              validation -- beg = 2008-01-01 00:00:00, end = 2008-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2009-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 10 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2010-01-01 00:00:00,  end = 2010-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2007-01-01 00:00:00, end = 2008-12-31 00:00:00     
              validation -- beg = 2009-01-01 00:00:00, end = 2009-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2010-01-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-02-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-05-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-09-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-10-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2010-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 11 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2011-01-01 00:00:00,  end = 2011-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2008-01-01 00:00:00, end = 2009-12-31 00:00:00     
              validation -- beg = 2010-01-01 00:00:00, end = 2010-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 12 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2012-01-01 00:00:00,  end = 2012-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2009-01-01 00:00:00, end = 2010-12-31 00:00:00     
              validation -- beg = 2011-01-01 00:00:00, end = 2011-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-02-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-11-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 13 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2013-01-01 00:00:00,  end = 2013-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2010-01-01 00:00:00, end = 2011-12-31 00:00:00     
              validation -- beg = 2012-01-01 00:00:00, end = 2012-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2013-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2013-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 14 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2014-01-01 00:00:00,  end = 2014-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2011-01-01 00:00:00, end = 2012-12-31 00:00:00     
              validation -- beg = 2013-01-01 00:00:00, end = 2013-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2014-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2014-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 15 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2015-01-01 00:00:00,  end = 2015-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2012-01-01 00:00:00, end = 2013-12-31 00:00:00     
              validation -- beg = 2014-01-01 00:00:00, end = 2014-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2015-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-03-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2015-12-14 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 16 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2016-01-01 00:00:00,  end = 2016-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2013-01-01 00:00:00, end = 2014-12-31 00:00:00     
              validation -- beg = 2015-01-01 00:00:00, end = 2015-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2016-01-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-02-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-03-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2016-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 17 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2017-01-01 00:00:00,  end = 2017-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2014-01-01 00:00:00, end = 2015-12-31 00:00:00     
              validation -- beg = 2016-01-01 00:00:00, end = 2016-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2017-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-07-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-08-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2017-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 18 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2018-01-01 00:00:00,  end = 2018-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2015-01-01 00:00:00, end = 2016-12-31 00:00:00     
              validation -- beg = 2017-01-01 00:00:00, end = 2017-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2018-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2018-12-13 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 19 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2019-01-01 00:00:00,  end = 2019-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2016-01-01 00:00:00, end = 2017-12-31 00:00:00     
              validation -- beg = 2018-01-01 00:00:00, end = 2018-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2019-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2019-12-12 00:00:00 
****************


*** 
*** Beg: WFA backtest iteration                     
***          Iter_No : 20 ,  WFA SW Name: SW-WFA-Backtest 5      
***          WFA SW   Obj Size:  0                
***          Slide Win -> Period : Months , Size : 20 
***          Anchor Start Fit Date  : False           
***          WFA SW Scenario Name : WFASlideWinScenarioSlidingDatasets             
***
        -- Test Period                              
              beg = 2020-01-01 00:00:00,  end = 2020-12-31 00:00:00                 
        -- Fit Datasets         
              train      -- beg = 2017-01-01 00:00:00, end = 2018-12-31 00:00:00     
              validation -- beg = 2019-01-01 00:00:00, end = 2019-12-31 00:00:00     



**************** 
**************** Current Sim. Date w/ Market Data = 2020-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-03-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-04-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-05-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-08-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-09-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-10-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-11-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2020-12-11 00:00:00 
****************

Backtest Metrics
Save to Excel
In [51]:
tsExecuteEngine_sw.getSummaryMetrics().to_excel("SW-WFA-Backtest-5 backtest-metrics.xlsx")
Execution & Investment Metrics

DOW

In [53]:
tsExecuteEngine_sw.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^DJI" ')
Out[53]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
1 1 20 Months ts_sma_1_^DJI No ^DJI Market 1 sma TA ... 2001-01-03 2001-12-31 -0.07 -0.07 -0.26 -0.2 0.06 -0.04
2 1 20 Months ts_sma_2_^DJI No ^DJI Market 1 sma TA ... 2001-01-03 2001-12-31 0.14 0.14 0.8 -0.11 0.06 -0.04
3 1 20 Months ts_sma_3_^DJI No ^DJI Market 1 sma TA ... 2001-01-03 2001-12-31 0.12 0.13 0.72 -0.11 0.06 -0.04
4 1 20 Months ts_sma_4_^DJI No ^DJI Market 1 sma TA ... 2001-01-03 2001-12-31 -0.03 -0.03 -0.09 -0.15 0.06 -0.04
5 1 20 Months ts_sma_5_^DJI No ^DJI Market 1 sma TA ... 2001-01-03 2001-12-31 -0.02 -0.02 -0.02 -0.18 0.06 -0.04
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4377 20 20 Months ts_sma_5_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.35 0.35 1.08 -0.13 0.13 -0.13
4378 20 20 Months ts_sma_6_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.21 0.21 0.74 -0.13 0.13 -0.13
4379 20 20 Months ts_sma_7_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.23 0.23 0.8 -0.13 0.13 -0.13
4380 20 20 Months all_All_sl_tsl_atr_5_^DJI No ^DJI Stop_Loss_And_Trail_SL 7 composite ... atr TA 2020-01-03 2020-12-31 0.25 0.25 0.85 -0.13 0.13 -0.13
4398 20 20 Months Long-Only Trade Strategy for ^DJI No ^DJI Market None None None ... 2020-01-03 2020-12-31 0.06 0.06 0.34 -0.37 0.11 -0.13

1460 rows × 23 columns

Nasdaq

In [54]:
tsExecuteEngine_sw.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^IXIC" ')
Out[54]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
9 1 20 Months ts_sma_1_^IXIC No ^IXIC Market 1 sma TA ... 2001-01-03 2001-12-31 -0.15 -0.15 -0.2 -0.39 0.08 -0.15
10 1 20 Months ts_sma_2_^IXIC No ^IXIC Market 1 sma TA ... 2001-01-03 2001-12-31 0.01 0.01 0.22 -0.27 0.08 -0.15
11 1 20 Months ts_sma_3_^IXIC No ^IXIC Market 1 sma TA ... 2001-01-03 2001-12-31 -0.11 -0.11 -0.12 -0.32 0.08 -0.15
12 1 20 Months ts_sma_4_^IXIC No ^IXIC Market 1 sma TA ... 2001-01-03 2001-12-31 -0.0 -0.0 0.18 -0.25 0.08 -0.15
13 1 20 Months ts_sma_5_^IXIC No ^IXIC Market 1 sma TA ... 2001-01-03 2001-12-31 -0.03 -0.03 0.14 -0.33 0.08 -0.15
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4385 20 20 Months ts_sma_5_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.12 0.12 0.49 -0.15 0.14 -0.12
4386 20 20 Months ts_sma_6_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.01 0.01 0.2 -0.16 0.14 -0.12
4387 20 20 Months ts_sma_7_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 -0.01 -0.01 0.16 -0.15 0.14 -0.12
4388 20 20 Months all_All_sl_tsl_atr_5_^IXIC No ^IXIC Stop_Loss_And_Trail_SL 7 composite ... atr TA 2020-01-03 2020-12-31 0.02 0.02 0.24 -0.13 0.14 -0.12
4397 20 20 Months Long-Only Trade Strategy for ^IXIC No ^IXIC Market None None None ... 2020-01-03 2020-12-31 0.42 0.42 1.16 -0.3 0.09 -0.12

1460 rows × 23 columns

S&P 500

In [55]:
tsExecuteEngine_sw.getSummaryMetrics()\
[ [ 'wfa_sw_iter_no', 'wfa_slide_win_size', 'wfa_slide_win_period',
    'ta_reg_item_name', 'is_portfolio', 'trade_asset', 'order_type',
    'enter_num_models', 'enter_model', 'enter_model_type',
    'exit_num_models', 'exit_model', 'exit_model_type',
    'stop_model', 'stop_model_type',
    'Start Period', 'End Period', 
    'Cumulative Return ', 'CAGR%', 'Sharpe', 'Max Drawdown ', 'Best Day ', 'Worst Day '] ].\
        query('trade_asset == "^GSPC" ')
Out[55]:
wfa_sw_iter_no wfa_slide_win_size wfa_slide_win_period ta_reg_item_name is_portfolio trade_asset order_type enter_num_models enter_model enter_model_type ... stop_model stop_model_type Start Period End Period Cumulative Return CAGR% Sharpe Max Drawdown Best Day Worst Day
17 1 20 Months ts_sma_1_^GSPC No ^GSPC Market 1 sma TA ... 2001-01-03 2001-12-31 -0.07 -0.07 -0.28 -0.24 0.04 -0.05
18 1 20 Months ts_sma_2_^GSPC No ^GSPC Market 1 sma TA ... 2001-01-03 2001-12-31 0.07 0.07 0.46 -0.11 0.04 -0.05
19 1 20 Months ts_sma_3_^GSPC No ^GSPC Market 1 sma TA ... 2001-01-03 2001-12-31 0.08 0.08 0.53 -0.13 0.04 -0.05
20 1 20 Months ts_sma_4_^GSPC No ^GSPC Market 1 sma TA ... 2001-01-03 2001-12-31 -0.1 -0.1 -0.46 -0.2 0.04 -0.05
21 1 20 Months ts_sma_5_^GSPC No ^GSPC Market 1 sma TA ... 2001-01-03 2001-12-31 -0.03 -0.03 -0.05 -0.15 0.04 -0.05
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4393 20 20 Months ts_sma_5_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.22 0.23 0.83 -0.12 0.1 -0.11
4394 20 20 Months ts_sma_6_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.14 0.14 0.59 -0.12 0.1 -0.11
4395 20 20 Months ts_sma_7_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 1 sma TA ... atr TA 2020-01-03 2020-12-31 0.12 0.13 0.54 -0.12 0.1 -0.11
4396 20 20 Months all_All_sl_tsl_atr_5_^GSPC No ^GSPC Stop_Loss_And_Trail_SL 7 composite ... atr TA 2020-01-03 2020-12-31 0.1 0.1 0.47 -0.12 0.1 -0.11
4399 20 20 Months Long-Only Trade Strategy for ^GSPC No ^GSPC Market None None None ... 2020-01-03 2020-12-31 0.15 0.15 0.59 -0.34 0.09 -0.12

1460 rows × 23 columns

Reports

The reports currently supported are provided by quantstats, https://github.com/ranaroussi/quantstats.

  • Guidelines:
    1. Run a backtest (Backtest, WFA Backtest )
    2. Select the Report to execute
    3. Select a trade strategy from the backtest for the report
    4. Optional, select a trade strategy from the backtest to use as a benchmark for the report
In [ ]:
from trade_engine.reports.BacktestReports import BacktestReports

WFA-Backtest for Reports

Description:

  • Portfolio has a subset of the trade strategies in Portfolio G

Backtest:

1. Type: WFA Backtest
2. AI Models Fit Date Ranges
    1. Training Period: 
        1. Begin Date = 2008-05-01 
        2. End Date   = 2010-04-30  
    2. Validation Period: 
        1. Begin Date = 2010-05-01 
        2. End Date   = 2010-12-31   
4. Test Period: 
    1. Begin Date = 2011-01-01 
    2. End Date   = 2012-12-31  

Portfolio Trade Assets

In [210]:
portfolio_trade_assets   = [ "^DJI", "^IXIC", "^GSPC" ]

Market Data Manager

In [211]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "1980-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData_From_1980",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 

Simulation Broker

In [212]:
brokerTradingObj = SimBrokerTrading()

Enter & Exit Models

In [213]:
tsConfDat = TradeStrategyConfigData()

# Set Config

tsConfDat.tsSetConfig(\
    ts_set_conf_dict = 
           { 'set_actions_conf' : 
                      { "entry" : { 'votingPolicy' : 1, 'incNoInvestInVotingDec' : False,
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1, 'cross_over_signal_for_trading' : False },
                        "exit"  : { 'votingPolicy' : 1, 
                                    'minPerVotingLong' : 0.0, 'minPerVotingShort' : 0.0,
                                    'lastn_match' : 1 } 
                      }
           } )
           
# TS #1

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_1", 
    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps' : 50, 'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'         : 20 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 } },
                             },
                    }  )

# TS #2

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_lstm", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "lstm",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'         : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn'   : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )
# TS #3
    
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_conv1d_gru", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "conv1d_gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'   : 50,   'no_neurons_lay1'    : 20,
                                                 'no_neurons_lay2' : 20,   'pred_ahead_periods' : 5,
                                                 'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                                 'epochs'          : 20 }  
                                }
                            } }  )

# TS #8
tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_gru_2", 
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "gru",
                                  'type'     : "ai",
                                  'obj_args' : { 'n_steps'          : 40,   'no_neurons_lay1'    : 20,
                                         'no_neurons_lay2' : 20,   'pred_ahead_periods' : 3,
                                         'ext_trade_dyn'   : True, 're_eval_exit_dyn' : True,
                                         'epochs'          : 20 }  
                                }
                            } }  )

# TS #10

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma_2",    
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 15, 'win_slow' : 60 } ,
                                  'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                                  'exit_policy_args'   : { 'lastn_match' : 1 },
                                },
                            }  } )

# TS #16

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_kama",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "kama",
                              'type'     : "ta",
                              'obj_args' : { 'window_fast' : 10, 'pow1_fast' : 2, 'pow2_fast'  : 30,
                                             'window_slow' : 10, 'pow1_slow' : 5, 'pow2_slow'  : 30 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )
# TS #17

tsConfDat.addTSConf(\
   ts_conf_dict = { 
      'ts_unique_tag' : "ts_tsi",    
      'actions_conf'  : { "entry_exit" :  
                            { 'model'    : "tsi",
                              'type'     : "ta",
                              'obj_args' : { 'window_slow' : 25, 'window_fast' : 5 },
                              'entry_policy_args'  : { 'lastn_match' : 1, 'cross_enter_signal' : False },
                              'exit_policy_args'   : { 'lastn_match' : 1 },
                            },
                        }  } )

Trade Strategies, Trade Investment Manager, and Trade Asset Register Items

In [214]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio For Reports",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1
                      )

Training, Validation and Test Periods for Backtest

In [215]:
training_period = DatasetDef(datasetType = DatasetType.Training,
                             strBegDateAIModels = "2007-11-01",
                             strBegDate         = "2008-05-01",
                             strEndDate         = "2010-04-30" )

validation_period = DatasetDef(datasetType = DatasetType.Validation,
                               strBegDateAIModels = "2009-11-01",
                               strBegDate         = "2010-05-01",
                               strEndDate         = "2010-12-31" )

testing_period = DatasetDef(datasetType = DatasetType.Testing,
                               strBegDateAIModels = "2010-07-01",
                               strBegDate         = "2011-01-01",
                               strEndDate         = "2012-12-31" )

fit_datasets = FitDatasetsDef( trainingDataset    = training_period,
                               validationDataset  = validation_period )

Execute WFA Backtest

In [216]:
tsExecuteEngine = BacktestExecutionWFA( \
            name                        = "WFA Backtest for Reports",
            test_period                 = testing_period,
            fit_datasets_start          = fit_datasets,
            trade_asset_registered_item = portf_registered_obj,
            wfa_slide_win_size          = 4,
            wfa_slide_win_period        = WFASlideWindowPeriod.Months, 
            anchor_fit_dataset          = False )                      
In [217]:
tsExecuteEngine.evaluate()
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-03 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-01-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-03-29 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-04-27 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-05-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-06-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-07-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-08-19 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2011-09-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-10-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-11-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2011-12-13 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-01-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-02-10 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-03-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-04-10 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-05-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-06-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-07-05 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-08-30 00:00:00 
****************

**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  GRU_Model
**** Fitting Model:  LSTM_Model
**** Fitting Model:  Conv1d_GRU_Model
**** Fitting Model:  GRU_Model


**************** 
**************** Current Sim. Date w/ Market Data = 2012-09-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-10-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-11-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2012-12-27 00:00:00 
****************

Backtest Metrics

In [225]:
tsExecuteEngine.getExecutionMetrics().query('Is_Portfolio == "Yes"')
Out[225]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 Portfolio For Reports None None None Yes 0 719 54000000.0 5.561412e+07 0.0 0.029891 Completed
Trade Strategies Execution & Investment Metrics

DOW Jones

In [218]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("DJI")', engine='python')
Out[218]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
1 ts_gru_1_^DJI No 34 2000000.0 2.125266e+06 0.062633 Completed
2 ts_lstm_^DJI No 29 2000000.0 2.207503e+06 0.103752 Completed
3 ts_conv1d_gru_^DJI No 21 2000000.0 2.133629e+06 0.066815 Completed
4 ts_gru_2_^DJI No 34 2000000.0 2.125266e+06 0.062633 Completed
5 ts_sma_2_^DJI No 11 2000000.0 1.809485e+06 -0.095257 Completed
6 ts_kama_^DJI No 6 2000000.0 1.924585e+06 -0.037708 Completed
7 ts_tsi_^DJI No 32 2000000.0 1.768477e+06 -0.115761 Completed
8 all_All_^DJI No 26 2000000.0 1.816221e+06 -0.091889 Completed
25 Long-Only Trade Strategy for ^DJI No 1 2000000.0 2.245110e+06 0.122555 Completed

Nasdaq

In [219]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("IXIC")', engine='python')
Out[219]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
9 ts_gru_1_^IXIC No 50 2000000.0 1.966694e+06 -0.016653 Completed
10 ts_lstm_^IXIC No 27 2000000.0 2.679671e+06 0.339836 Completed
11 ts_conv1d_gru_^IXIC No 33 2000000.0 2.579703e+06 0.289851 Completed
12 ts_gru_2_^IXIC No 50 2000000.0 1.966694e+06 -0.016653 Completed
13 ts_sma_2_^IXIC No 17 2000000.0 1.541490e+06 -0.229255 Completed
14 ts_kama_^IXIC No 8 2000000.0 1.523835e+06 -0.238082 Completed
15 ts_tsi_^IXIC No 31 2000000.0 1.715325e+06 -0.142337 Completed
16 all_All_^IXIC No 40 2000000.0 2.490758e+06 0.245379 Completed
26 Long-Only Trade Strategy for ^IXIC No 1 2000000.0 2.243697e+06 0.121848 Completed

S&P 500

In [220]:
tsExecuteEngine.getExecutionMetrics()[ ['TA_Reg_Name', 'Is_Portfolio', 'Num_Trades_Completed',
        'Init_Capital', 'Final_Capital', 'Cum_Return', 'Backtest_Status']].\
        query('TA_Reg_Name.str.contains("GSPC")', engine='python')
Out[220]:
TA_Reg_Name Is_Portfolio Num_Trades_Completed Init_Capital Final_Capital Cum_Return Backtest_Status
17 ts_gru_1_^GSPC No 50 2000000.0 2.087149e+06 0.043574 Completed
18 ts_lstm_^GSPC No 43 2000000.0 2.630430e+06 0.315215 Completed
19 ts_conv1d_gru_^GSPC No 32 2000000.0 1.967512e+06 -0.016244 Completed
20 ts_gru_2_^GSPC No 50 2000000.0 2.087149e+06 0.043574 Completed
21 ts_sma_2_^GSPC No 13 2000000.0 2.052107e+06 0.026054 Completed
22 ts_kama_^GSPC No 6 2000000.0 1.819147e+06 -0.090427 Completed
23 ts_tsi_^GSPC No 31 2000000.0 1.752484e+06 -0.123758 Completed
24 all_All_^GSPC No 42 2000000.0 2.112140e+06 0.056070 Completed
27 Long-Only Trade Strategy for ^GSPC No 1 2000000.0 2.242591e+06 0.121295 Completed

Full Tearsheet Report for a Trade Strategy

Composite Nasdaq Trade Strategy vs Nasdaq

In [222]:
BacktestReports.createTearsheetReport(\
                    backtest                   = tsExecuteEngine,
                    ta_reg_item_name           = "all_All_^IXIC",
                    ta_reg_item_benchmark_name = "Long-Only Trade Strategy for ^IXIC ", # optional
                    report_type                = "full" )

Performance Metrics

                           Strategy    Benchmark
-------------------------  ----------  -----------
Start Period               2011-01-04  2011-01-04
End Period                 2012-12-31  2012-12-31
Risk-Free Rate             0.0%        0.0%
Time in Market             100.0%      100.0%

Cumulative Return          24.92%      12.18%
CAGR%                      11.82%      5.94%

Sharpe                     0.6         0.38
Sortino                    0.9         0.54
Sortino/√2                 0.64        0.38

Max Drawdown               -24.82%     -18.71%
Longest DD Days            410         277
Volatility (ann.)          22.91%      20.75%
R^2                        0.25        0.25
Calmar                     0.48        0.32
Skew                       0.17        -0.29
Kurtosis                   2.39        3.24

Expected Daily %           0.04%       0.02%
Expected Monthly %         0.93%       0.48%
Expected Yearly %          11.77%      5.92%
Kelly Criterion            -9.33%      -2.65%
Risk of Ruin               0.0%        0.0%
Daily Value-at-Risk        -2.32%      -2.12%
Expected Shortfall (cVaR)  -2.32%      -2.12%

Gain/Pain Ratio            0.11        0.07
Gain/Pain (1M)             0.67        0.51

Payoff Ratio               0.83        0.84
Profit Factor              1.11        1.07
Common Sense Ratio         1.41        1.09
CPC Index                  0.46        0.48
Tail Ratio                 1.27        1.02
Outlier Win Ratio          3.3         3.99
Outlier Loss Ratio         3.33        3.49

MTD                        -0.33%      0.31%
3M                         7.23%       -3.1%
6M                         -1.42%      2.88%
YTD                        -14.05%     15.9%
1Y                         -14.05%     15.9%
3Y (ann.)                  11.82%      5.94%
5Y (ann.)                  11.82%      5.94%
10Y (ann.)                 11.82%      5.94%
All-time (ann.)            11.82%      5.94%

Best Day                   6.82%       5.29%
Worst Day                  -6.9%       -6.9%
Best Month                 18.38%      11.14%
Worst Month                -8.1%       -7.19%
Best Year                  45.34%      15.9%
Worst Year                 -14.05%     -3.21%

Avg. Drawdown              -4.42%      -3.36%
Avg. Drawdown Days         32          37
Recovery Factor            1.0         0.65
Ulcer Index                1.03        1.08

Avg. Up Month              4.44%       3.9%
Avg. Down Month            -2.98%      -1.21%
Win Days %                 50.5%       53.09%
Win Month %                54.17%      54.17%
Win Quarter %              75.0%       50.0%
Win Year %                 50.0%       50.0%
Beta                       -0.55       -
Alpha                      0.18        -
None

5 Worst Drawdowns

Start Valley End Days Max Drawdown 99% Max Drawdown
1 2011-11-17 2012-09-14 2012-12-31 410 -24.821542 -24.622778
2 2011-06-20 2011-07-07 2011-08-04 45 -8.650895 -8.216971
3 2011-03-14 2011-04-29 2011-06-17 95 -8.638741 -8.604618
4 2011-10-06 2011-10-14 2011-10-27 21 -8.434783 -8.010882
5 2011-08-05 2011-08-15 2011-08-18 13 -8.079396 -7.771761

Strategy Visualization

Composite DJI Trade Strategy vs DJI

In [223]:
BacktestReports.createTearsheetReport(\
                    backtest                   = tsExecuteEngine,
                    ta_reg_item_name           = "all_All_^DJI",
                    ta_reg_item_benchmark_name = "Long-Only Trade Strategy for ^DJI ", # optional
                    report_type                = "full" )

Performance Metrics

                           Strategy    Benchmark
-------------------------  ----------  -----------
Start Period               2011-01-04  2011-01-04
End Period                 2012-12-31  2012-12-31
Risk-Free Rate             0.0%        0.0%
Time in Market             100.0%      100.0%

Cumulative Return          -9.19%      12.26%
CAGR%                      -4.72%      5.98%

Sharpe                     -0.17       0.43
Sortino                    -0.24       0.59
Sortino/√2                 -0.17       0.42

Max Drawdown               -23.47%     -16.79%
Longest DD Days            452         277
Volatility (ann.)          18.36%      17.02%
R^2                        0.33        0.33
Calmar                     -0.2        0.36
Skew                       -0.18       -0.41
Kurtosis                   2.56        3.7

Expected Daily %           -0.02%      0.02%
Expected Monthly %         -0.4%       0.48%
Expected Yearly %          -4.7%       5.95%
Kelly Criterion            -19.95%     -16.21%
Risk of Ruin               0.0%        0.0%
Daily Value-at-Risk        -1.91%      -1.73%
Expected Shortfall (cVaR)  -1.91%      -1.73%

Gain/Pain Ratio            -0.03       0.08
Gain/Pain (1M)             -0.18       0.6

Payoff Ratio               0.7         0.7
Profit Factor              0.97        1.08
Common Sense Ratio         0.93        1.06
CPC Index                  0.34        0.39
Tail Ratio                 0.96        0.98
Outlier Win Ratio          3.64        3.91
Outlier Loss Ratio         3.86        4.37

MTD                        -0.64%      0.6%
3M                         4.69%       -2.47%
6M                         -1.03%      1.74%
YTD                        -7.07%      7.24%
1Y                         -7.07%      7.24%
3Y (ann.)                  -4.72%      5.98%
5Y (ann.)                  -4.72%      5.98%
10Y (ann.)                 -4.72%      5.98%
All-time (ann.)            -4.72%      5.98%

Best Day                   4.61%       4.23%
Worst Day                  -5.52%      -5.53%
Best Month                 8.32%       9.52%
Worst Month                -6.52%      -6.2%
Best Year                  -2.28%      7.24%
Worst Year                 -7.07%      4.68%

Avg. Drawdown              -5.1%       -2.31%
Avg. Drawdown Days         70          27
Recovery Factor            -0.39       0.73
Ulcer Index                1.07        1.08

Avg. Up Month              2.73%       1.89%
Avg. Down Month            -6.52%      -4.35%
Win Days %                 50.7%       52.1%
Win Month %                33.33%      66.67%
Win Quarter %              62.5%       62.5%
Win Year %                 0.0%        100.0%
Beta                       -0.62       -
Alpha                      0.01        -
None

5 Worst Drawdowns

Start Valley End Days Max Drawdown 99% Max Drawdown
1 2011-10-06 2012-10-05 2012-12-31 452 -23.473114 -23.225049
2 2011-08-04 2011-08-08 2011-10-04 61 -9.098417 -8.726727
3 2011-06-16 2011-07-21 2011-08-02 47 -6.276415 -6.239083
4 2011-03-14 2011-04-29 2011-06-10 88 -6.265508 -6.264366
5 2011-02-02 2011-02-18 2011-03-07 33 -2.903729 -2.662719

Strategy Visualization

Portfolio

In [226]:
BacktestReports.createTearsheetReport(\
                    backtest                   = tsExecuteEngine,
                    ta_reg_item_name           = "Portfolio For Reports",
                    ta_reg_item_benchmark_name = None, # optional
                    report_type                = "full" )

Performance Metrics

                           Strategy
-------------------------  ----------
Start Period               2011-01-04
End Period                 2012-12-31
Risk-Free Rate             0.0%
Time in Market             100.0%

Cumulative Return          3.06%
CAGR%                      1.52%

Sharpe                     0.22
Sortino                    0.32
Sortino/√2                 0.23

Max Drawdown               -6.97%
Longest DD Days            210
Volatility (ann.)          8.63%
Calmar                     0.22
Skew                       0.22
Kurtosis                   6.13

Expected Daily %           0.01%
Expected Monthly %         0.13%
Expected Yearly %          1.52%
Kelly Criterion            2.14%
Risk of Ruin               0.0%
Daily Value-at-Risk        -0.89%
Expected Shortfall (cVaR)  -0.89%

Gain/Pain Ratio            0.05
Gain/Pain (1M)             0.25

Payoff Ratio               1.06
Profit Factor              1.05
Common Sense Ratio         1.12
CPC Index                  0.55
Tail Ratio                 1.08
Outlier Win Ratio          4.71
Outlier Loss Ratio         4.66

MTD                        -0.85%
3M                         0.33%
6M                         -2.4%
YTD                        -3.25%
1Y                         -3.25%
3Y (ann.)                  1.52%
5Y (ann.)                  1.52%
10Y (ann.)                 1.52%
All-time (ann.)            1.52%

Best Day                   3.3%
Worst Day                  -2.77%
Best Month                 7.22%
Worst Month                -1.95%
Best Year                  6.52%
Worst Year                 -3.25%

Avg. Drawdown              -1.85%
Avg. Drawdown Days         36
Recovery Factor            0.44
Ulcer Index                1.04

Avg. Up Month              1.87%
Avg. Down Month            -1.08%
Win Days %                 49.7%
Win Month %                41.67%
Win Quarter %              62.5%
Win Year %                 50.0%
None

5 Worst Drawdowns

Start Valley End Days Max Drawdown 99% Max Drawdown
1 2012-06-04 2012-09-14 2012-12-31 210 -6.971465 -6.916440
2 2011-06-27 2011-08-08 2011-08-25 59 -5.124048 -4.940863
3 2011-11-17 2012-04-02 2012-06-01 197 -4.970649 -4.936728
4 2011-10-06 2011-10-14 2011-11-14 39 -4.602706 -4.479153
5 2011-08-26 2011-08-31 2011-09-09 14 -3.861942 -3.580027

Strategy Visualization

HTML Tearsheet Reports

In [227]:
BacktestReports.createHTMLTearsheetReport(\
                    backtest                   = tsExecuteEngine,
                    ta_reg_item_name           = "all_All_^IXIC",
                    ta_reg_item_benchmark_name = "Long-Only Trade Strategy for ^IXIC ", # optional
                    title                      = 'Strategy Tearsheet', 
                    download_filename          = 'ts-tearsheet.html' ) 

Other

Trade Fee Policy

Description:

1. $2.0M Budget
2. 100% capital invested
3. Apply 1% fit per trade transaction

Trade Strategies:

1. One trade strategy: Nasdaq using Simple Moving Average(SMA) for entering/exiting a trade

Backtest:

1. Type: regular
2. Test Period: 
    1. Begin Date = 2001-01-01 
    2. End Date   = 2005-12-31 
Trade Asset
In [201]:
trade_assets   = [ "^IXIC" ]
Market Data Manager
In [202]:
dirPathMarketData = '/Users/gustavozambrana/Google Drive/Python/Projects/Trade_Engine/Data/US_Market_Indixes'

supportedTradeAssets   = [ "^DJI", "^IXIC", "^GSPC", "UDOW", "SDOW", "SPXL", "SPXS", "TQQQ", "SQQQ" ]
beg_date_str           = "2000-01-01"
end_date_str           = None

ts_marketdat_mng = TradeStrategyMarketDataMng(\
        marketDataProviderName = "yahoofinance",
        supportedTradeAssets   = supportedTradeAssets,
        stock_price_col_name   = "Adj Close",
        fileNameMarketData     = "US_Indixes_And_ETFs_MrkData",
        dirPathMarketData      = dirPathMarketData,
        beg_date_str           = beg_date_str,
        end_date_str           = end_date_str,
        interval               = "1d"  ) 
Simulation Broker
In [203]:
brokerTradingObj = SimBrokerTrading()
Enter & Exit Model
In [204]:
tsConfDat = TradeStrategyConfigData()

# SMA JSON Configuration
#
# Model Configuration:
#                win_fast   : fast moving average
#                win_slow   : slow moving average
# Signals to enter and exit a trade based on the fast ma crossing the slow ma

tsConfDat.addTSConf(\
   ts_conf_dict = { 
          'ts_unique_tag' : "ts_sma",     
          'actions_conf'  : { "entry_exit" :  
                                { 'model'    : "sma",
                                  'type'     : "ta",
                                  'obj_args' : { 'win_fast' : 20, 'win_slow' : 100 } },
                            } } )
Trade Strategy, Trade Investment Manager, and Trade Asset Register Item
In [205]:
taRegItemGen = TradeAssetRegisterItemGenerator()

portf_registered_obj = taRegItemGen.createTARegItem(
                           name_ta_reg_item        = "Portfolio Test Fee Policy",
    
                           # *** Trade Assets & Market Data
                           portfolio_trade_assets  = portfolio_trade_assets,
                           ts_marketdat_mng        = ts_marketdat_mng,
                           dirPathMarketData       = dirPathMarketData,
                           market_data_period      = MarketDataPeriod.Day,

                           # *** Broker
                           brokerTradingObj        = brokerTradingObj,

                           # *** T.S. Permutations for each of the following sets of models
                           enter_exit_config_models = tsConfDat,

                           # *** Investment Manager Params 
                           minPeriodsBetweenTrades                 = 1,
                           initInvestmentPerTradeStrategy          = 2000000.0, 
                           capPercentToInvestPerTrade              = 100.0,
                           minInvestPercent                        = 5.0,
                           enter_trade_next_open_period            = True,
                           min_account_balance                     = 1000.0,
                           portfRebalanceFreq                      = PortfolioRebalanceFrequency.Never,
                           portfRebalancePeriods                   = 1,
    
                           # *** Fee Policy Params per Trade
                           tradeFeeType                            = TradeFeeType.FixPercentPerTransactionValue,
                           percentPerTransaction                   = 0.01    # 1% per trade
                      )
Execute Backtest
In [207]:
tsExecuteEngine = BacktestExecution( \
                    name = "Backtest for Testing Trade Fee Policy - flat fee per transaction",
                    timePeriod = DatasetDef(datasetType = DatasetType.Testing,
                                            strBegDate = "2001-01-01", 
                                            strEndDate = "2005-12-31" ),
                    trade_asset_registered_item = portf_registered_obj )
In [208]:
tsExecuteEngine.evaluate()

**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-04-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-05-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-06-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-09-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-10-22 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-11-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2001-12-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-01-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-02-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-03-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-04-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-05-14 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-06-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-07-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-08-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-09-06 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-10-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-11-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-02 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2002-12-31 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-01-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-02-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-03-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-04-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-05-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-06-24 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-07-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-08-20 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-09-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-10-16 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-11-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2003-12-12 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-01-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-02-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-03-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-04-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-05-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-06-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-07-07 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-08-04 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-01 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-09-30 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-10-28 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-11-26 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2004-12-27 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-01-25 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-02-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-03-23 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-04-21 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-05-19 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-06-17 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-07-18 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-08-15 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-09-13 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-10-11 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-11-08 00:00:00 
****************



**************** 
**************** Current Sim. Date w/ Market Data = 2005-12-07 00:00:00 
****************

Backtest Metrics
Execution & Investment Metrics
In [209]:
tsExecuteEngine.getExecutionMetrics()
Out[209]:
TA_Reg_Name TA_Reg_Id Inv_Mng_Id Inv_Mng_Parent_Id Is_Portfolio Num_Trades_Executing Num_Trades_Completed Init_Capital Final_Capital Final_Inv_Capital Cum_Return Backtest_Status
0 Portfolio Test Fee Policy None None None Yes 0 67 12000000.0 1.114697e+07 0.0 -0.071086 Completed
1 ts_sma_^DJI None None None No 0 24 2000000.0 1.647423e+06 0.0 -0.176289 Completed
2 ts_sma_^IXIC None None None No 0 22 2000000.0 1.630125e+06 0.0 -0.184938 Completed
3 ts_sma_^GSPC None None None No 0 18 2000000.0 1.986038e+06 0.0 -0.006981 Completed
4 Long-Only Trade Strategy for ^DJI None None None No 0 1 2000000.0 2.013342e+06 0.0 0.006671 Completed
5 Long-Only Trade Strategy for ^IXIC None None None No 0 1 2000000.0 1.924537e+06 0.0 -0.037731 Completed
6 Long-Only Trade Strategy for ^GSPC None None None No 0 1 2000000.0 1.945501e+06 0.0 -0.027249 Completed